Deep Copy vs JSON Stringify / JSON Parse

Benchmark created by ramesaliyev 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

Revisions

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