Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
Object.fromEntries vs reduce vs. for-of
Turning an array into an object
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/150.0.0.0 Safari/537.36
Browser:
Chrome 150
Operating system:
Linux
Device Platform:
Desktop
Date tested:
24 days ago
Benchmark engine:
Benchmark.js
For-of
26K/s
Reduce (reuse object)
26K/s
Object.fromEntries
14K/s
Reduce (creating temporary objects)
3K/s
View exact numbers
Test name
Executions per second
✓
For-of
25,994 Ops/sec
Reduce (reuse object)
25,516 Ops/sec
Object.fromEntries
13,825 Ops/sec
Reduce (creating temporary objects)
2,677 Ops/sec
Script Preparation code:
function rand() { return Math.floor(Math.random() * 10000) } var data = Array(1000).fill(0).map((_, i) => ({ i, a: rand(), b: rand() }))
Tests:
Object.fromEntries
Object.fromEntries(data.map(({i, ...rest}) => [i, rest]));
Reduce (reuse object)
data.reduce((acc, {i, ...rest}) => { acc[i] = rest; return acc; }, {});
Reduce (creating temporary objects)
Object.entries(data).reduce((acc, {i, ...rest}) => ({ ...acc, [i]: rest }), {});
For-of
const result = {} for (const {i, ...rest} of data) { result[i] = rest; }