Test name | Executions per second |
---|---|
Object.fromEntries | 2083.2 Ops/sec |
Reduce (reuse object) | 11273.2 Ops/sec |
Reduce (creating temporary objects) | 110.4 Ops/sec |
Map | 1915.1 Ops/sec |
forEach | 11514.9 Ops/sec |
for of | 12648.8 Ops/sec |
for i | 1244.0 Ops/sec |
for i saved length variable | 2267.3 Ops/sec |
var data = Array.from(Array(10000).keys()).map(i => ({id: i, value: `val_${i}`}));
Object.fromEntries(data.map(obj => [obj.id, obj]));
data.reduce((acc, obj) => {
acc[obj.id] = obj;
return acc;
}, {});
data.reduce((acc, obj) => ({
acc,
[obj.id]: obj
}), {});
new Map(data.map(obj => [obj.id, obj]));
const res = {};
data.forEach(obj => {
res[obj.id] = obj;
});
const res = {};
for (const obj of data) {
res[obj.id] = obj;
}
const res = {};
for (let i = 0; i < data.length; i++) {
const obj = data[i];
res[obj.id] = obj;
}
const res = {};
const length = data.length;
for (let i = 0; i < length; i++) {
const obj = data[i];
res[obj.id] = obj;
}