Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
JSON.stringify vs structuredClone vs simple deepCopyObject
JSON.stringify vs structuredClone vs simple deepCopyObject
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Browser:
Chrome 126
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
JSON.stringify
1497551.0 Ops/sec
structuredClone
856547.8 Ops/sec
deepCopyObject
1326036.0 Ops/sec
Script Preparation code:
var deepCopyObject = (inObject) => { if (inObject instanceof Date) return inObject if (inObject instanceof Set) return new Set(inObject) if (inObject instanceof Map) return new Map(inObject) if (typeof inObject !== 'object' || inObject === null) { return inObject // Return the value if inObject is not an object } // Create an array or object to hold the values const outObject = Array.isArray(inObject) ? [] : {} Object.keys(inObject).forEach((key) => { const value = inObject[key] // Recursively (deep) copy for nested objects, including arrays outObject[key] = typeof value === 'object' && value !== null ? deepCopyObject(value) : value }) return outObject } var MyObject = { description: 'Creates a deep copy of source, which should be an object or an array.', myNumber: 123456789, myBoolean: true, jayson: { stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....', parse: 'JSON.parse() method parses a JSON string...' } }; var myCopy = null;
Tests:
JSON.stringify
myCopy = JSON.parse(JSON.stringify(MyObject));
structuredClone
myCopy = structuredClone(MyObject);
deepCopyObject
myCopy = deepCopyObject(MyObject);