Deep Copy vs JSON Stringify / JSON Parse

JavaScript performance comparison

Revision 45 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  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}}, t: new Date(2011, 1, 20, 10,20), reg: /test/ig, b: false, n: new String('aaaa')}
  

};
</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
Deep Copy
var bes = deepCopy(uc)
pending…
JSON Stringify / JSON Parse
var bes = JSON.parse(JSON.stringify(uc))
pending…
deepClone
var bes2 = deepClone(uc)
pending…
cloneB
var bes3 = cloneB(uc)
pending…
cloneC
var besC = cloneC(uc)
pending…
Array.from
var besA = Array.from(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