Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
structuredClone vs deepClone vs JSON in large objects
(version: 1)
This benchmark creates huge objects to be cloned by lodash's cloneDeep function vs the native structuredClone
Comparing performance of:
cloneDeep vs structuredClone vs json
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js"></script>
Script Preparation code:
function createComplexNestedObject(depth = 10, breadth = 5, level = 1) { const result = {}; if (level < depth) result[`deepStart_${level}`] = createComplexNestedObject(depth, breadth, level + 1); for (let index = 0; index < breadth; index++) { const opts = [ `val_${level}_${index}_` + 'x'.repeat(50) /* string */, level * 1e3 + index /* number */, index % 2 === 0 /* boolean */, null /* null */, [index, level, `s${index}`] /* array */, new Date(Date.UTC(2020 + level, index % 12, (index % 28) + 1)) /* date */, new RegExp(`p_${level}_${index}`) /* regexp */ ]; result[`field_${level}_${index}`] = opts[index % opts.length]; if (level < depth && index === Math.floor(breadth / 2)) result[`deepMid_${level}`] = createComplexNestedObject(depth, breadth, level + 1); } if (level < depth) result[`deepEnd_${level}`] = createComplexNestedObject(depth, breadth, level + 1); return result; } var MyObject = createComplexNestedObject(10, 8); var myCopy = null;
Tests:
cloneDeep
myCopy = _.cloneDeep(MyObject)
structuredClone
myCopy = structuredClone(MyObject);
json
myCopy = JSON.parse(JSON.stringify(MyObject));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
cloneDeep
structuredClone
json
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
8 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36
Browser/OS:
Chrome 141 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
cloneDeep
9.7 Ops/sec
structuredClone
18.5 Ops/sec
json
12.3 Ops/sec
Related benchmarks:
Lodash cloneDeep vs for loop vs JSON parse vs recursive clone deep vs recursive reduce clone deep
Lodash cloneDeep vs freeze vs monokee deepClone
Lodash cloneDeep vs deepFreeze vs deepClone vs JSON.parse(JSON.stringify())
big clonedeep
LargeObject Lodash cloneDeep vs structuredClone vs JSON Parse
Lodash cloneDeep vs structuredClone vs Custom Implementation
Deep Clone vs JSON.Stringify vs structuredClone
JSON.parse(JSON.stringify())1 vs structuredClone
structuredClone vs deepClone in large objects
Comments
Confirm delete:
Do you really want to delete benchmark?