Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
js merge objects
(version: 1)
Comparing performance of:
Object.assign mutate vs Spread new
Created:
5 months ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Tests:
Object.assign mutate
function bench(label, fn, iterations = 50) { // Warmup fn(); const t0 = performance.now(); for (let i = 0; i < iterations; i++) fn(); const t1 = performance.now(); console.log(`${label}: ${(t1 - t0).toFixed(2)} ms over ${iterations} runs`); } // Example usage const a = buildOnject(100000); const b = buildOnject(10000); const target1 = structuredClone(a); // or {...a} if shallow const target2 = structuredClone(a); // or {...a} if shallow bench('Object.assign mutate', () => { Object.assign(target1, b); }); function buildOnject(size = 1) { const random = Math.random(1); const out = {}; for (let i = 0; i <= size; i++) { out[random + i] = i; } return out; }
Spread new
function bench(label, fn, iterations = 50) { // Warmup fn(); const t0 = performance.now(); for (let i = 0; i < iterations; i++) fn(); const t1 = performance.now(); console.log(`${label}: ${(t1 - t0).toFixed(2)} ms over ${iterations} runs`); } // Example usage const a = buildOnject(100000); const b = buildOnject(10000); const target1 = structuredClone(a); // or {...a} if shallow const target2 = structuredClone(a); // or {...a} if shallow bench('Spread new', () => { const merged = { ...a, ...b }; }); function buildOnject(size = 1) { const random = Math.random(1); const out = {}; for (let i = 0; i <= size; i++) { out[random + i] = i; } return out; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Object.assign mutate
Spread new
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
5 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36
Browser/OS:
Chrome 142 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Object.assign mutate
6.3 Ops/sec
Spread new
0.8 Ops/sec
Related benchmarks:
Adding fields to functions
Array loop
_.union VS. indexOf + push
javascript-performance-call-function-inside-for-loop
Scoping test
Map generator test
Push vs Spread vs Double loop Ultimate
name23
objct1 vs function1
Comments
Confirm delete:
Do you really want to delete benchmark?