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