Script Preparation code:
x
 
function copyX(x) {
  return {
    a: x.a,
    b: x.b,
    c: {
      a: x.c.a
    }
  }
}
function cloneObject(obj) {
    var clone = {};
    for(var i in obj) {
        if(obj[i] != null &&  typeof(obj[i])=="object")
            clone[i] = cloneObject(obj[i]);
        else
            clone[i] = obj[i];
    }
    return clone;
}
var x = {
  a: 444,
  b: 666,
  c: {
    a: "dddd"
  }
}
Tests:
  • JSON

     
    JSON.parse(JSON.stringify(x))
  • Copy (no generic)

     
    copyX(x)
  • Copy (generic)

     
    cloneObject(x)
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    JSON
    Copy (no generic)
    Copy (generic)

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one year ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2.1 Safari/605.1.15
Safari 17 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
JSON 1529252.0 Ops/sec
Copy (no generic) 6160773.5 Ops/sec
Copy (generic) 2802696.0 Ops/sec