Deep Copy vs JSON Stringify / JSON Parse

JavaScript performance comparison

Revision 89 of this test case created by Jonathan Perry

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function reduceArray (array) {
      return array.reduce((a, c) => a.concat(deepCopy(c)), [])
  }
  
  function deepCopyObject (object) {
      const r = {};
      for (k in v) {
          const c = object[k];
          r[k] = deepCopy(c);
      }
      return r;    
  }
  
  function deepCopy(v) {
      if (Array.isArray(v)) return reduceArray(v);
      if ((v || false) instanceof Object) return deepCopyObject(v)
      return v;
  }
  
  var uc = {bir:{iki:{uc:3}}}

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
JSON Stringify / JSON Parse
var bes = JSON.parse(JSON.stringify(uc))
pending…
Deep Copy
var bes = deepCopy(uc)
pending…

Compare results of other browsers

Revisions

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

0 Comments