Deep Copy vs JSON Stringify / JSON Parse

JavaScript performance comparison

Revision 90 of this test case created by Jonathan Perry

Preparation code

Benchmark.prototype.setup = function() {
  function reduceArray (array) {
      return array.reduce((a, c) => a.concat(deepCopy(c)), [])
  function deepCopyObject (object) {
      const r = {};
      for (k in object) {
          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}}}


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))
Deep Copy
var bes = deepCopy(uc)

Compare results of other browsers


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