Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash groupBy vs Array.reduce 100k fair2
(version: 0)
Comparing performance of:
Lodash vs Native vs groupByReduce vs groupByReduceBetter vs groupByHasOwnProperty vs groupByMapBetter vs native direct vs native direct no copy
Created:
4 years ago
by:
Guest
Jump to the latest result
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; var data = []; for (var i = 0; i <= max2; i++) { data.push({ id: i }); } function groupByReduce(arr, iteratee) { return arr.reduce((acc, v) => { const k = iteratee(v); (acc[k] || (acc[k] = [])).push(v) return acc; }, {}) } function groupByReduceBetter(arr, iteratee) { return arr.reduce((acc, v) => { const k = iteratee(v); if(acc[k]) { acc[k].push(v); } else { acc[k] = [v]; } return acc; }, {}) } function groupByHasOwnProperty(arr, iteratee) { return arr.reduce((acc, v) => { const k = iteratee(v); if(acc.hasOwnProperty(k)) { acc[k].push(v); } else { acc[k] = [v]; } return acc; }, {}) } function groupByMap(arr, iteratee) { const m = new Map(); for (const v of arr) { const k = iteratee(v); const temp = m.get(k) ?? []; temp.push(v); m.set(k, temp) } return m; } function groupByMapBetter(arr, iteratee) { const m = new Map(); for (let length = arr.length, i = 0; i < length; ++i) { const k = iteratee(arr[i]); let temp = m.get(k); if (temp) { temp.push(arr[i]); } else { temp = [arr[i]] } m.set(k, temp) } return m; } var iteratee = ({ id }) => id
Tests:
Lodash
_.groupBy(data, iteratee)
Native
data.reduce((acc, item) => { if(acc[item.id]) { acc[item.id].push(item); } else { acc[item.id] = [item]; } return acc; }, {})
groupByReduce
groupByReduce(data, iteratee)
groupByReduceBetter
groupByReduceBetter(data, iteratee)
groupByHasOwnProperty
groupByHasOwnProperty(data, iteratee)
groupByMapBetter
groupByMapBetter(data, iteratee)
native direct
data.reduce((acc, v) => { const k = v.id; if(acc[k]) { acc[k].push(v); } else { acc[k] = [v]; } return acc; }, {})
native direct no copy
data.reduce((acc, v) => { if(acc[v.id]) { acc[v.id].push(v); } else { acc[v.id] = [v]; } return acc; }, {})
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (8)
Previous results
Fork
Test case name
Result
Lodash
Native
groupByReduce
groupByReduceBetter
groupByHasOwnProperty
groupByMapBetter
native direct
native direct no copy
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
It looks like you're sharing some benchmark results from a browser performance testing scenario. If I had to summarize the findings, I'd say: * The tests show varying execution speeds for different functions (e.g., `groupByReduceBetter`, `Lodash`, etc.) in the Chrome 97 browser. * The `Native` test seems to be performing better than the others, with a slightly higher average execution speed. * Some tests, like `native direct no copy` and `Native`, have similar execution speeds. However, I don't see any specific questions or areas of concern that need to be addressed. Could you please provide more context or clarify what you'd like me to help with?
Related benchmarks:
lodash groupBy vs Array.reduce (1mln)
lodash groupBy vs Array.reduce vs Array.group 100k
lodash groupBy vs Array.reduce 100k better 2
lodash groupBy vs Array.reduce vs simple for loop
lodash groupBy vs Array.reduce group by 100k
Comments
Confirm delete:
Do you really want to delete benchmark?