Test name | Executions per second |
---|---|
with spread operator | 1564674.5 Ops/sec |
with mutation | 6755363.5 Ops/sec |
with object assign | 314272.8 Ops/sec |
with new object assign | 127982.2 Ops/sec |
foreach | 6649769.0 Ops/sec |
var 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
}
}, {})
range(0, 10).reduce((acc, num) => {
acc[num] = num
return acc
}, {})
range(0, 10).reduce((acc, num) => {
return Object.assign(acc, {[num]: num})
}, {})
range(0, 10).reduce((acc, num) => {
return Object.assign({}, acc, {[num]: num})
}, {})
const output = {};
range(0, 10).forEach((num) => {
output[num] = num;
});