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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/151.0.0.0 Safari/537.36
Browser:
Chrome 151
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one month ago
Benchmark engine:
Benchmark.js
Reduce (reuse object)
31K/s
For-of
31K/s
Object.fromEntries
19K/s
Reduce (creating temporary objects)
4K/s
View exact numbers
Test name
Executions per second
✓
Reduce (reuse object)
30,820 Ops/sec
For-of
30,559 Ops/sec
Object.fromEntries
18,977 Ops/sec
Reduce (creating temporary objects)
4,364 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; }