Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash cloneDeep vs structuredClone vs simpleCloneDeep
(version: 1)
https://developer.mozilla.org/en-US/docs/Web/API/structuredClone
Comparing performance of:
Lodash cloneDeep vs Native structuredClone vs Simple cloneDeep
Created:
10 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...' }, arr: [{ test: 1 }, { test: 2 }, { test: { a: 1 } }] }; var myCopy = null; function simpleCloneDeep(obj) { if (typeof obj !== 'object' || obj === null) { return obj; } let result; if ( (typeof obj.length === 'number' && obj instanceof Array) || // fix: instanceof Array 在IDE模拟器的iframe环境中判断为 false Object.prototype.toString.call(obj) === '[object Array]' ) { const { length } = obj; result = new Array(length); for (let i = 0; i < length; i += 1) { result[i] = simpleCloneDeep(obj[i]); } return result; } // ios10 上,proxy 对象 Object.prototype.toString.call(obj)返回 '[object,ProxyObject]' switch (Object.prototype.toString.call(obj)) { case '[object Map]': result = new Map(); obj.forEach((subValue, key) => { result.set(key, simpleCloneDeep(subValue)); }); return result; case '[object Set]': result = new Set(); obj.forEach((subValue) => { result.add(simpleCloneDeep(subValue)); }); return result; default: result = {}; for (const i in obj) { if (Object.prototype.hasOwnProperty.call(obj, i)) { result[i] = simpleCloneDeep(obj[i]); } } return result; } }
Tests:
Lodash cloneDeep
myCopy = _.cloneDeep(MyObject);
Native structuredClone
myCopy = structuredClone(MyObject);
Simple cloneDeep
myCopy = simpleCloneDeep(MyObject);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Lodash cloneDeep
Native structuredClone
Simple cloneDeep
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one month ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36 Edg/145.0.0.0
Browser/OS:
Chrome 145 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash cloneDeep
273347.0 Ops/sec
Native structuredClone
164494.4 Ops/sec
Simple cloneDeep
916017.9 Ops/sec
Related benchmarks:
Lodash cloneDeep vs structuredClone vs recursiveDeepCopy vs JSON clone 10kb json
Lodash cloneDeep vs structuredClone deep array
Lodash cloneDeep vs structuredClone vs JSON.stringify with array values
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 vs recursiveDeepCopy vs JSON clone with a more deep test
Lodash cloneDeep vs structuredClone 2asdasdas
Lodash cloneDeep vs structuredClone 2asdasdasrgdfg
Comments
Confirm delete:
Do you really want to delete benchmark?