Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
JSON.stringify + JSON.parse vs structuredClone vs fast_deep_clone (recursive)
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/147.0.0.0 Safari/537.36 Edg/147.0.0.0
Browser:
Chrome 147
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
4 months ago
Benchmark engine:
Benchmark.js
fast_deep_clone()
10.6M/s
JSON.parse(JSON.stringify())
2.9M/s
structuredClone()
1.1M/s
View exact numbers
Test name
Executions per second
✓
fast_deep_clone()
10,610,915 Ops/sec
JSON.parse(JSON.stringify())
2,864,904 Ops/sec
structuredClone()
1,135,910 Ops/sec
Script Preparation code:
var obj = { 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.parse(JSON.stringify())
JSON.parse(JSON.stringify(obj));
structuredClone()
structuredClone(obj);
fast_deep_clone()
const fast_deep_clone = (obj) => { function cloneArray(a, fn) { var keys = Object.keys(a); var a2 = new Array(keys.length) for (const key of keys) { var k = keys[key]; var cur = a[k]; if (typeof cur !== 'object' || cur === null) { a2[k] = cur; } else { a2[k] = fn(cur); } } return a2; } if (typeof obj !== 'object' || obj === null) return obj; if (obj instanceof Date) return new Date(obj); if (Array.isArray(obj)) return cloneArray(obj, fast_deep_clone); if (obj.toString() !== '[object Object]') { return obj.toString(); } let value, key; const keys = Object.keys(obj); const outObject = {}; for (key of keys) { if (key) { value = obj[key]; outObject[key] = fast_deep_clone(value); } } return outObject; }; fast_deep_clone(obj);