lodash groupBy vs Array.reduce (2)
Date tested:
4 years ago
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36
Test name
Executions per second
Lodash
138.8 Ops/sec
Native
273.5 Ops/sec
Benchmark definition (click to collapse):
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
var max2 = 100000; // 100,000,000 (100 Million) var data = []; for (var i = 0; i <= max2; i++) { data.push({ id: i }); }
Tests:
Lodash
_.groupBy(data, ({ id }) => id)
Native
data.reduce((acc, item) => { acc[item.id] = item; return acc; }, {})
Open this result on MeasureThat.net