Obj clone

JavaScript performance comparison

Test case created by Sombressoul

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  let iterationsLimit = 1000;
  let originalObject = {a: 1, b: 2, c: {d: 3, e: 4}};
  
  function deepClone(obj) {
    const clObj = {};
    for(const i in obj) {
      if (obj[i] instanceof Object) {
        clObj[i] = deepClone(obj[i]);
        continue;
      }
      clObj[i] = obj[i];
    }
    return clObj;
  }

};
</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
for (let i = 0; i < iterationsLimit; i++) {
  let clonedObject = JSON.parse(JSON.stringify(originalObject));
}
pending…
uDef Func
for (let i = 0; i < iterationsLimit; i++) {
  let clonedObject = deepClone(originalObject);
}
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