Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0
Firefox 121
Windows
Desktop
one year ago
Test name Executions per second
JSON 208.8 Ops/sec
structuredClone 441.5 Ops/sec
Script Preparation code:
AخA
 
function createBigObject(depth) {
    const obj = {};
    for (let i = 0; i < 5000; i++) {
        obj[i + Math.floor(Math.random() * 10000)] = {
            [Math.random() * 10000]: Math.random() * 10000,
        };
    }
    return obj;
}
var bigObj = createBigObject()
var clone;
Tests:
  • JSON

     
    clone = JSON.parse(JSON.stringify(bigObj))
  • structuredClone

     
    clone = structuredClone(bigObj)