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 (Windows NT 10.0; Win64; x64; rv:139.0) Gecko/20100101 Firefox/139.0
Browser:
Firefox 139
Operating system:
Windows
Device Platform:
Desktop
Date tested:
11 months ago
Test name
Executions per second
Object.fromEntries with Array.map
3651.4 Ops/sec
new Map with Array.map
1373.0 Ops/sec
Reduce (reusing object)
7057.3 Ops/sec
Reduce (creating temporary objects)
0.3 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]);