Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Deep copy algo vs JSON manipulation
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/129.0.0.0 Safari/537.36
Browser:
Chrome 129
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
JSON copy
1294626.1 Ops/sec
Deep copy
793125.4 Ops/sec
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);