Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
fromEntries vs.reduce vs. forEach
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/126.0.0.0 Safari/537.36
Browser:
Chrome 126
Operating system:
Linux
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Object.fromEntries
360983.5 Ops/sec
Reduce (reuse object)
912376.9 Ops/sec
Reduce (creating temporary objects)
273347.4 Ops/sec
Plain
625320.5 Ops/sec
Script Preparation code:
const CHARS = 'abcdefghijklmnopqrstuvwxyz'; const RANDOM_KEY_LENGTH = 6; const SAMPLE_SIZE = 200; function getRandChar() { return CHARS.at(Math.floor(Math.random() * CHARS.length)); } var items = Array.from({ length: SAMPLE_SIZE }, (_, index) => `${index}${Array.from({ length: RANDOM_KEY_LENGTH }, getRandChar).join('')}`);
Tests:
Reduce (creating temporary objects)
const result = items.reduce((acc, [item]) => ({ ...acc, [item]: 1 }), {}); return result;
Reduce (reuse object)
const result = items.reduce((acc, item) => { acc[item] = 1; return acc; }, {}); return result;
Object.fromEntries
const result = Object.fromEntries(items.map((item) => [item, 1])); return result;
Plain
const result = {}; items.forEach((item) => { result[item] = 1; }); return result;