HTML Preparation code:
x
 
1
2
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
 
var max2 = 500000;
var data = [];
for (var i = 0; i <= max2; i++) { data.push({ id: i }); }
Tests:
  • Lodash

     
    _.groupBy(data, ({ id }) => id)
  • Native

     
    // Using reduce to mimic _.groupBy
    const grouped = data.reduce((acc, item) => {
        // Initialize an array for this id if it doesn't exist
        if (!acc[item.id]) acc[item.id] = [];
        // Push the item into the array for this id
        acc[item.id].push(item);
        return acc;
    }, {});
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Lodash
    Native

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 5 months ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0
Chrome 130 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
Lodash 68.3 Ops/sec
Native 40.3 Ops/sec