Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
JavaScript spread operator vs Object.assign performance vs a custom merge object method
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Browser:
Chrome 121
Operating system:
Linux
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
Using the spread operator
8640652.0 Ops/sec
Using Object.assign
5470456.0 Ops/sec
Using custom merge method (Create a clone object)
1495925.0 Ops/sec
Script Preparation code:
var firstObject = { sampleData: 'Hello world' } var secondObject = { moreData: 'foo bar' } var merge = (def, opt) => { if (!opt) return def for (const key in def) { if (!Object.prototype.hasOwnProperty.call(opt, key) || opt[key] === undefined) opt[key] = def[key] else if (opt[key] === Object(opt[key])) opt[key] = merge(def[key], opt[key]) } return opt }
Tests:
Using the spread operator
const finalObject = { ...firstObject, ...secondObject }
Using Object.assign
const finalObject = Object.assign(firstObject, secondObject)
Using custom merge method (Create a clone object)
const finalObject = merge(firstObject, secondObject)