JSON.parse + JSON.stringify vs _.cloneDeep (v6)

Revision 6 of this benchmark created by mickey on


Preparation HTML

<script src="https://cdn.rawgit.com/lodash/lodash/1f40b2f908bd908ebf587cf8465a0427a7c4436d/dist/lodash.js"></script>

Setup

var x = {
    a: {
    b: {
    c: {
    d: {
    e: {
    f: {
    g: {
    h: {
    i: {
    j: {
    k: {
    l: {
    m: [1,2,3,4,5]
    }
    }
    }
    }
    }
    }
    }
    }
    }
    }
    }
    }
    };

Test runner

Ready to run.

Testing in
TestOps/sec
JSON.parse + JSON.stringify
var ergebnis = JSON.parse(JSON.stringify(x))
ready
_.cloneDeep
var ergebnis = _.cloneDeep(x);
ready
[].map
var ergebnis = x.map(function(y){ // calling map on object?
  _.clone(y);
});
ready

Revisions

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