Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Lodash cloneDeep vs structuredClone vs simpleCloneDeep
https://developer.mozilla.org/en-US/docs/Web/API/structuredClone
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/141.0.0.0 Safari/537.36
Browser:
Chrome 141
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
6 months ago
Test name
Executions per second
Lodash cloneDeep
933623.8 Ops/sec
Native structuredClone
660066.2 Ops/sec
Simple cloneDeep
3861044.5 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...' }, 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);