Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Deep copy algo vs JSON manipulation - 120k lines of prices
(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."); }; function generate_data() { let data = { 'prices': [], 'other_prices' : [], 'my object': [ {'object a': 'object object'}, {'object b': 'object object'}, {'object c': 'object object', 'objectd': 36}, 5 ] }; // Helper function to generate random product names function generateProductName() { const products = ['Laptop', 'Phone', 'Tablet', 'Headphone', 'Speaker', 'Monitor', 'Keyboard', 'Mouse', 'Smartwatch', 'Camera']; const adjectives = ['Super', 'Ultra', 'Pro', 'Max', 'Plus', 'Lite', 'Mini', 'Advanced', 'Portable', 'Wireless']; const randomProduct = products[Math.floor(Math.random() * products.length)]; const randomAdjective = adjectives[Math.floor(Math.random() * adjectives.length)]; return `${randomAdjective} ${randomProduct}`; } // Helper function to generate random prices function generatePrice() { return (Math.random() * 1000).toFixed(2); // Random price between 0 and 1000 with 2 decimal places } // Generate 6000 product name and price entries for (let i = 0; i < 60000; i++) { const product = generateProductName(); const price = generatePrice(); data['prices'].push({ 'product': product, 'price': parseFloat(price) }); } for (let i = 0; i < 60000; i++) { const product = generateProductName(); const price = generatePrice(); data['other_prices'].push({ 'product': product, 'price': parseFloat(price) }); } return data; }; var data = generate_data();
Tests:
JSON copy
a = JSON.parse(JSON.stringify(data));
Deep copy
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 (Macintosh; Intel Mac OS X 10.15; rv:132.0) Gecko/20100101 Firefox/132.0
Browser/OS:
Firefox 132 on Mac OS X 10.15
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
JSON copy
37.3 Ops/sec
Deep copy
111.9 Ops/sec
Related benchmarks:
Closure v Prototypical Objects 3
object cope speed test
Deep Clone vs JSON.Stringify
DeepFreeze vs Lodash cloneDeep vs JSON Clone
Deep Clone vs JSON.Stringify vs structuredClone
Deep copy algo vs JSON manipulation
Deep copy algo vs JSON manipulation - 6k lines of prices
Comments
Confirm delete:
Do you really want to delete benchmark?