Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object spread vs Object.assign vs simple assignement
(version: 1)
Comparing performance of:
spread vs Object.assign vs manually assigning
Created:
4 months ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
const firstObject = {} firstObject.key1 = 'Hello world'; firstObject.key2 = 'foo bar'; firstObject.key3 = '42'; firstObject.key4 = 'Hitch Hikers Guide to the Galaxy'; const secondObject = {} firstObject.key3 = 'Hello world'; firstObject.key4 = 'foo bar'; firstObject.key5 = '42'; firstObject.key6 = 'Hitch Hikers Guide to the Galaxy';
Tests:
spread
const firstObject = {} firstObject.key1 = 'Hello world'; firstObject.key2 = 'foo bar'; firstObject.key3 = '42'; firstObject.key4 = 'Hitch Hikers Guide to the Galaxy'; const secondObject = {} firstObject.key3 = 'Hello world'; firstObject.key4 = 'foo bar'; firstObject.key5 = '42'; firstObject.key6 = 'Hitch Hikers Guide to the Galaxy'; const output = { ...firstObject, ...secondObject }
Object.assign
const firstObject = {} firstObject.key1 = 'Hello world'; firstObject.key2 = 'foo bar'; firstObject.key3 = '42'; firstObject.key4 = 'Hitch Hikers Guide to the Galaxy'; const secondObject = {} firstObject.key3 = 'Hello world'; firstObject.key4 = 'foo bar'; firstObject.key5 = '42'; firstObject.key6 = 'Hitch Hikers Guide to the Galaxy'; // Note this does modify and return the first object, doesn't create a new one const output = Object.assign(firstObject, secondObject);
manually assigning
const firstObject = {} firstObject.key1 = 'Hello world'; firstObject.key2 = 'foo bar'; firstObject.key3 = '42'; firstObject.key4 = 'Hitch Hikers Guide to the Galaxy'; const secondObject = {} firstObject.key3 = 'Hello world'; firstObject.key4 = 'foo bar'; firstObject.key5 = '42'; firstObject.key6 = 'Hitch Hikers Guide to the Galaxy'; // Note this does modify and return the first object, doesn't create a new one for (const key in secondObject) { firstObject[key] = secondObject[key] } const output = firstObject;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
spread
Object.assign
manually assigning
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:147.0) Gecko/20100101 Firefox/147.0
Browser/OS:
Firefox 147 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
spread
7216038.0 Ops/sec
Object.assign
21834066.0 Ops/sec
manually assigning
20081378.0 Ops/sec
Related benchmarks:
Object Spread vs Assign
Object.assign vs key assign
conditionally insert properties
Object assign vs Property change
overwrite object properties
destructuring vs creating
Test 03
JS Destruction vs Assign
Spread vs Object.assign vs Object.create
Comments
Confirm delete:
Do you really want to delete benchmark?