Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
JSON.stringify vs structuredClone vs cloneLineageData vs cloneDeep
JSON.stringify vs structuredClone vs cloneLineageData vs cloneDeep
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/127.0.0.0 Safari/537.36
Browser:
Chrome 127
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
JSON.stringify
478523.2 Ops/sec
structuredClone
501116.2 Ops/sec
cloneLineageData
651536.2 Ops/sec
lodash.cloneDeep
495595.4 Ops/sec
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
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...' }, mySet: new Set([1,2,3,1]), myList: [1,3,4,5,67,'ab'], myDate: new Date(), }; var myCopy = null;
Tests:
JSON.stringify
myCopy = JSON.parse(JSON.stringify(MyObject));
structuredClone
myCopy = structuredClone(MyObject);
cloneLineageData
const cloneLineageData = (toClone) => { if (typeof toClone !== 'object' || toClone === null) return toClone; if (toClone instanceof Set) { return new Set(toClone); } if (Array.isArray(toClone)) { return toClone.map(cloneLineageData); } if (toClone instanceof Date) { return new Date(toClone); } const cloned = { ...toClone }; const clonedObjKeys = Object.keys(cloned); for (let i = 0; i < clonedObjKeys.length; i += 1) { const key = clonedObjKeys[i]; cloned[key] = cloneLineageData(cloned[key]); } return cloned; }; myCopy = cloneLineageData(MyObject);
lodash.cloneDeep
myCopy = _.cloneDeep(MyObject);