Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Map from .reduce vs Map from .map vs Map from generator function
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:135.0) Gecko/20100101 Firefox/135.0
Browser:
Firefox 135
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Map from .reduce
3587.1 Ops/sec
Map from .map
2369.5 Ops/sec
Map from generator function
1413.7 Ops/sec
Script Preparation code:
var arr10k = Array.from(Array(10000)).map((x, i) => ({ x1: i, x2: i * 2, x4: i * 4 })); function* getItems() { for (const x of arr10k) { yield [x.x1, x]; } }
Tests:
Map from .reduce
arr10k.reduce((acc, x) => acc.set(x.x1, x), new Map());
Map from .map
new Map(arr10k.map(x => [x.x1, x]));
Map from generator function
new Map(getItems());