Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
lodash groupBy vs Object.groupBy 500k
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
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
Browser:
Chrome 130
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Lodash
59.6 Ops/sec
Native
12.2 Ops/sec
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js"></script>
Script Preparation code:
const max2 = 500000; var rows = []; for (let i = 0; i <= max2; i++) { // Use `let` for `i` as it’s updated in each loop iteration rows.push({ id: i, task_id: i % 1000, name: `Task ${i}`, status: i % 2 === 0 ? 'active' : 'inactive', description: `Description for task ${i}`, priority: Math.floor(Math.random() * 5) + 1 }); }
Tests:
Lodash with _.mapValues and _.omit
const lodashMapValuesOmitGrouped = _.mapValues(_.groupBy(rows, 'task_id'), group => group.map(row => _.omit(row, 'task_id')) );
Native reduce Grouping with Destructuring
const nativeReduceGrouped = rows.reduce((acc, row) => { const { task_id, ...rest } = row; // Exclude `task_id` using destructuring if (!acc[task_id]) acc[task_id] = []; // Initialize array for this `task_id` acc[task_id].push(rest); // Add the item without `task_id` to the group return acc; }, {});
Custom reduce with Object.keys Filtering
const customReduceGrouped = rows.reduce((acc, row) => { if (!acc[row.id]) acc[row.id] = []; // Initialize an array for each unique id const rowData = Object.keys(row).reduce((obj, key) => { if (key !== 'id') obj[key] = row[key]; // Exclude 'id' to avoid nesting return obj; }, {}); acc[row.id].push(rowData); return acc; }, {});
Lodash Grouping with Native Key Removal
const lodashGroupedWithDelete = _.groupBy(rows, 'task_id'); Object.values(lodashGroupedWithDelete).forEach(group => { group.forEach(item => { delete item.task_id; // Remove `task_id` directly from each item }); });