Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Custom Reduce vs Vanilla JS Reduce vs _lodash Reduce with Map
Comparing the performance of the reduce functions on a Map
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser:
Chrome 131
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Vanilla JS Reduce on a Map
5.4 Ops/sec
Lodash Reduce on a Map
20.9 Ops/sec
Custom Reduce on a Map
104.4 Ops/sec
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js'></script>
Script Preparation code:
const reduce = (map, reducer, accumulator) => { let iter = map[Symbol.iterator](); let item; if (accumulator === undefined && (item = iter.next())) { if (item.done) return accumulator; accumulator = item.value[1]; } while ((item = iter.next()) && !item.done) accumulator = reducer(accumulator, item.value[1], item.value[0]); return accumulator; }; const randomMap = new Map(Array.from({length: 1000000}, (_, i) => [i, Math.floor(Math.random() * 100)])); const sumValues = (a, b) => a + b; const sumKeyValues = (a, b) => a + b[1];
Tests:
Vanilla JS Reduce on a Map
Array.from(randomMap).reduce(sumKeyValues, 0);
Lodash Reduce on a Map
_.reduce(_.toArray(randomMap), sumKeyValues, 0);
Custom Reduce on a Map
reduce(randomMap, sumValues, 0);