Deep Copy vs JSON Stringify / JSON Parse (v6)

Revision 6 of this benchmark created on


Setup

function deepCopy(o) {
        var copy = o,k;
     
        if (o && typeof o === 'object') {
            copy = Object.prototype.toString.call(o) === '[object Array]' ? [] : {};
            for (k in o) {
                copy[k] = deepCopy(o[k]);
            }
        }
     
        return copy;
    }
    
    var uc = {bir:{iki:{uc:3}}}

Test runner

Ready to run.

Testing in
TestOps/sec
Deep Copy
var bes = deepCopy(uc)
ready
JSON Stringify / JSON Parse
var bes = JSON.parse(JSON.stringify(uc))
ready
JSONStringify / JSONParse
var p = JSON.parse, s = JSON.stringify;
var bes = p(s(uc))
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.