Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Object spread vs Object.assign vs simple assignement
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:147.0) Gecko/20100101 Firefox/147.0
Browser:
Firefox 147
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 months ago
Test name
Executions per second
spread
7216038.0 Ops/sec
Object.assign
21834066.0 Ops/sec
manually assigning
20081378.0 Ops/sec
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;