Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Deep copy algo vs JSON manipulation
(version: 0)
Comparing performance of:
JSON copy vs Deep copy
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
function deepCopy(obj) { var copy; // Handle the 3 simple types, and null or undefined if (null == obj || "object" != typeof obj) return obj; // Handle Date if (obj instanceof Date) { copy = new Date(); copy.setTime(obj.getTime()); return copy; } // Handle Array if (obj instanceof Array) { copy = []; for (var i = 0, len = obj.length; i < len; i++) { copy[i] = deepCopy(obj[i]); } return copy; } // Handle Object if (obj instanceof Object) { copy = {}; for (var attr in obj) { if (obj.hasOwnProperty(attr)) copy[attr] = deepCopy(obj[attr]); } return copy; } throw new Error("Unable to copy obj! Its type isn't supported."); };
Tests:
JSON copy
const data = {'my object' : [{'object a' : 'object object'},{'object b' : 'object object'}, {'object c' : 'object object', 'objectd': 36}, 5]} a = JSON.parse(JSON.stringify(data));
Deep copy
const data = {'my object' : [{'object a' : 'object object'},{'object b' : 'object object'}, {'object c' : 'object object', 'objectd': 36}, 5]} a = deepCopy(data);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
JSON copy
Deep copy
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Browser/OS:
Chrome 130 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
JSON copy
563373.0 Ops/sec
Deep copy
351385.4 Ops/sec
Related benchmarks:
Lodash cloneDeep vs for loop vs JSON parse vs recursive clone deep vs recursive reduce clone deep
Closure v Prototypical Objects 3
object cope speed test
Deep Clone vs JSON.Stringify
Deep Clone vs JSON.Stringify vs structuredClone
Deep copy algo vs JSON manipulation - 6k lines of prices
Deep copy algo vs JSON manipulation - 120k lines of prices
Comments
Confirm delete:
Do you really want to delete benchmark?