Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Object.fromEntries vs new Map vs Reduce
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 with Array.map
1825.0 Ops/sec
new Map with Array.map
1243.9 Ops/sec
Reduce (reusing object)
8147.5 Ops/sec
Reduce (creating temporary objects)
57.2 Ops/sec
Script Preparation code:
var ids = Array.from(Array(10000).keys()) var data = ids.map(item => ({ id: item, random: Math.random() }))
Tests:
Object.fromEntries with Array.map
// Create the dictionary // Using `Object.fromEntries` and `Array.map` const dictionary = Object.fromEntries( data.map((item) => [ // Key item.id, // Item item, ]) ); // Utilize it, to test the performance of the dictionary itself as well. ids.map((id) => dictionary[id]);
new Map with Array.map
// Create the dictionary // Using `new Map` and `Array.map` const dictionary = new Map( data.map((item) => [ // Key item.id, // Item item, ]) ); // Utilize it, to test the performance of the dictionary itself as well. ids.map((id) => dictionary.get(id));
Reduce (reusing object)
// Create the dictionary // Using `Array.reduce` // And reusing the object const dictionary = data.reduce((obj, item) => { obj[item.id] = item; return obj; }, {}); // Utilize it, to test the performance of the dictionary itself as well. ids.map((id) => dictionary[id]);
Reduce (creating temporary objects)
// Create the dictionary // Using `Array.reduce` // And NOT reusing the object const dictionary = data.reduce((obj, item) => { return { ...obj, [item.id]: item }; }, {}); // Utilize it, to test the performance of the dictionary itself as well. ids.map((id) => dictionary[id]);