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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0
Browser:
Chrome 120
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
Benchmark engine:
Benchmark.js
Reduce (reuse object)
16K/s
For-of
15K/s
Object.fromEntries
8K/s
Reduce (creating temporary objects)
1K/s
View exact numbers
Test name
Executions per second
✓
Reduce (reuse object)
15,837 Ops/sec
For-of
15,048 Ops/sec
Object.fromEntries
7,586 Ops/sec
Reduce (creating temporary objects)
1,240 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; }