Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash cloneDeep vs structuredClone deep array vs deepClone
(version: 1)
https://developer.mozilla.org/en-US/docs/Web/API/structuredClone
Comparing performance of:
Lodash cloneDeep vs Native structuredClone vs custom deeClone
Created:
5 months ago
by:
Guest
Jump to the latest result
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...', jayson: { stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....', parse: 'JSON.parse() method parses a JSON string...', jayson: { stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....', parse: 'JSON.parse() method parses a JSON string...', jayson: { stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....', parse: 'JSON.parse() method parses a JSON string...' } } } } }; // pulled this from https://github.com/nodejs/node/issues/34355#issuecomment-658394617 function deepClone(o) { if (typeof o !== "object") { return o } if (!o) { return o } // https://jsperf.com/deep-copy-vs-json-stringify-json-parse/25 if (Array.isArray(o)) { const newO = [] for (let i = 0; i < o.length; i += 1) { const val = !o[i] || typeof o[i] !== "object" ? o[i] : deepClone(o[i]) newO[i] = val === undefined ? null : val } return newO } const newO = {} for (const i of Object.keys(o)) { const val = !o[i] || typeof o[i] !== "object" ? o[i] : deepClone(o[i]) if (val === undefined) { continue } newO[i] = val } return newO } var myCopy = null; var arr = [] var arr2 = [] for (let i = 0; i <=10000; i++) { arr.push(structuredClone(MyObject)) }
Tests:
Lodash cloneDeep
myCopy = _.cloneDeep(arr);
Native structuredClone
myCopy = structuredClone(arr);
custom deeClone
myCopy = deepClone(arr);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Lodash cloneDeep
Native structuredClone
custom deeClone
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
5 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36
Browser/OS:
Chrome 142 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash cloneDeep
61.3 Ops/sec
Native structuredClone
60.4 Ops/sec
custom deeClone
241.7 Ops/sec
Related benchmarks:
Lodash cloneDeep vs structuredClone 222222
Lodash cloneDeep vs structuredClone deep array
cloneDeep vs structuredClone
Lodash cloneDeep vs structuredClone vs JSON Parse (deep object)
Lodash cloneDeep vs structuredClone vs JSON-JSON
Lodash cloneDeep vs structuredClone vs JSON.parse + JSON.stringify but with big data
Lodash cloneDeep vs structuredClone 2asdasdas
Lodash cloneDeep vs structuredClone 2asdasdasrgdfg
Lodash cloneDeep vs structuredClone vs simpleCloneDeep
Comments
Confirm delete:
Do you really want to delete benchmark?