Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
spread vs mutation vs Object.assign for reduce callback vs for of loop vs for loop
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser:
Chrome 120
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
with spread operator
1752811.5 Ops/sec
with mutation
9694777.0 Ops/sec
with object assign
388366.2 Ops/sec
with for of loop
9808419.0 Ops/sec
with for loop
8310622.0 Ops/sec
Tests:
with spread operator
const range = (from, to) => { const output = [] for(var x = from; x < to; x++){ output.push(x) } return output } range(0, 10).reduce((acc, num) => { return { ...acc, [num]: num } }, {})
with mutation
const range = (from, to) => { const output = [] for(var x = from; x < to; x++){ output.push(x) } return output } range(0, 10).reduce((acc, num) => { acc[num] = num return acc }, {})
with object assign
const range = (from, to) => { const output = [] for(var x = from; x < to; x++){ output.push(x) } return output } range(0, 10).reduce((acc, num) => { return Object.assign(acc, {[num]: num}) }, {})
with for of loop
const range = (from, to) => { const output = [] for(var x = from; x < to; x++){ output.push(x) } return output } const items = range(0, 10); let result = {}; for(let item of items) { result[item] = item; }
with for loop
const range = (from, to) => { const output = [] for(var x = from; x < to; x++){ output.push(x) } return output } const items = range(0, 10); let result = {}; for(let i = 0; i < items.length; i += 1) { result[items[i]] = items[i]; }