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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36
Browser:
Chrome 125
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Object.fromEntries with Array.map
1473.7 Ops/sec
new Map with Array.map
1037.2 Ops/sec
Reduce (reusing object)
7626.3 Ops/sec
Reduce (creating temporary objects)
59.7 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]);