Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
Spread vs Object.assign vs Object.keys with forEach
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3 Safari/605.1.15
Browser:
Safari 18
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Benchmark engine:
Benchmark.js
Not merging
13.1M/s
Using Object.assign
12.4M/s
Using the spread operator
9.5M/s
View exact numbers
Test name
Executions per second
✓
Not merging
13,097,471 Ops/sec
Using Object.assign
12,372,391 Ops/sec
Using the spread operator
9,493,565 Ops/sec
Tests:
Using the spread operator
const firstObject = { sampleData: 'Hello world' } const secondObject = { moreData: 'foo bar' } const finalObject = { ...firstObject, ...secondObject };
Using Object.assign
const firstObject = { sampleData: 'Hello world' } const secondObject = { moreData: 'foo bar' } const finalObject = Object.assign(firstObject, secondObject);
Not merging
const firstObject = { sampleData: 'Hello world' } const secondObject = { moreData: 'foo bar' } const finalObject = {} Object.keys(firstObject).forEach(key => {finalObject[key] = firstObject[key] }) Object.keys(secondObject).forEach(key => {finalObject[key] = secondObject[key] })