Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Clone object
(version: 5)
Comparing performance of:
Manual clone vs Manual clone v2
Created:
4 months ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var object = { type: "FeatureCollection", features: [{ type: "Feature", properties: {}, geometry: { type: "Point", coordinates: [4.483605784808901, 51.907188449679325] } }, { "type": "Feature", "properties": {}, "geometry": { "type": "Polygon", "coordinates": [ [ [3.974369110811523, 51.907355547778565], [4.173944459020191, 51.86237166892457], [4.3808076710679416, 51.848867725914914], [4.579822414365026, 51.874487141880024], [4.534413416598767, 51.9495302480326], [4.365110733567974, 51.92360787140825], [4.179550508127079, 51.97336560819281], [4.018096293847009, 52.00236546429852], [3.9424146309028174, 51.97681895676649], [3.974369110811523, 51.907355547778565] ] ] } } ] }; var copy = null; // v1 function deepCloneJsonValue(value) { if (value === null || typeof value !== "object") return value; if (Array.isArray(value)) return deepCloneJsonArray(value); return deepCloneJsonObject(value); } function deepCloneJsonObject(obj) { const cloned = { ...obj }; for (const key in obj) { const value = obj[key]; if (typeof value !== "object" || value === null) continue; cloned[key] = Array.isArray(value) ? deepCloneJsonArray(value) : deepCloneJsonObject(value); } return cloned; } function deepCloneJsonArray(arr) { const cloned = []; for (let i = 0, len = arr.length; i !== len; i++) { cloned.push(deepCloneJsonValue(arr[i])); } return cloned; } // v2 function deepCloneJsonValue2(value) { if (value === null || typeof value !== "object") return value; if (Array.isArray(value)) return deepCloneJsonArray2(value); return deepCloneJsonObject2(value); } function deepCloneJsonObject2(obj) { const cloned = { ...obj }; for (const key in cloned) { const value = cloned[key]; if (typeof value !== "object" || value === null) continue; cloned[key] = Array.isArray(value) ? deepCloneJsonArray2(value) : deepCloneJsonObject2(value); } return cloned; } function deepCloneJsonArray2(arr) { const cloned = []; for (let i = 0, len = arr.length; i !== len; i++) { cloned.push(deepCloneJsonValue2(arr[i])); } return cloned; }
Tests:
Manual clone
copy = deepCloneJsonValue(object);
Manual clone v2
copy = deepCloneJsonValue2(object);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Manual clone
Manual clone v2
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
4 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0
Browser/OS:
Chrome 143 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Manual clone
2351042.0 Ops/sec
Manual clone v2
2344341.5 Ops/sec
Related benchmarks:
test clone
lodash vs json
Ramdajs
Lodash cloneDeep vs JSON clone vs structuredClone huge object 2
JS deep copy obj test
JS deep copy obj test2
lodash cloneDeep vs structuredClone on larger object and with arrays
JSON Parse vs StructuredClone bigger object
structuredClone vs JSON Stringify+Parse vs manual clone
Comments
Confirm delete:
Do you really want to delete benchmark?