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

Revision 32 of this benchmark created by Jt Whissel on


Setup

var x = {
    a: {
    b: {
    c: {
    d: {
    e: {
    f: {
    g: {
    h: {
    i: {
    j: {
    k: {
    l: {
    m: [1,2,3,4,5]
    }
    }
    }
    }
    }
    }
    }
    }
    }
    }
    }
    }
    };
  
  function loadScript(url, callback)
  {
      // adding the script tag to the head as suggested before
     var head = document.getElementsByTagName('head')[0];
     var script = document.createElement('script');
     script.type = 'text/javascript';
     script.src = url;
  
     // then bind the event to the callback function 
     // there are several events for cross browser compatibility
     script.onreadystatechange = callback;
     script.onload = callback;
  
     // fire the loading
     head.appendChild(script);
  }
  
  var lodash1 = null;
  var lodash4 = null;
  
  loadScript("https://cdnjs.cloudflare.com/ajax/libs/lodash.js/1.0.1/lodash.min.js", ()=>{
  lodash1 = _;
  
  loadScript("https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.min.js", ()=>{
  lodash4 = _;
  
  })
  
  })

Test runner

Ready to run.

Testing in
TestOps/sec
JSON.parse + JSON.stringify
var ergebnis = JSON.parse(JSON.stringify(x))
ready
lodash v4 cloneDeep
var ergebnis = lodash4.cloneDeep(x);
ready
lodash v1 cloneDeep
var ergebnis = lodash1.cloneDeep(x);
ready

Revisions

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