Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
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
Test name
Executions per second
Object.fromEntries
7585.7 Ops/sec
Reduce (reuse object)
15837.5 Ops/sec
Reduce (creating temporary objects)
1240.2 Ops/sec
For-of
15047.6 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; }