<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
var max2 = 100000;
var data = [];
for (var i = 0; i <= max2; i++) { data.push({ id: i }); }
_.groupBy(data, ({ id }) => id)
data.reduce((acc, item) => {
if (acc[item.id]) {
acc[item.id].push(item)
} else {
acc[item.id] = [item];
}
return acc;
}, {})
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Lodash | |
Native |
Test name | Executions per second |
---|---|
Lodash | 688.4 Ops/sec |
Native | 723.6 Ops/sec |
Let's break down the benchmark and its components.
What is being tested?
MeasureThat.net is testing the performance difference between two approaches for grouping an array of objects based on a specific property:
groupBy
function from the Lodash library, which groups an array by a specified function.Array.reduce()
method.Options compared
The benchmark is comparing the performance of these two approaches:
groupBy
function from Lodash is used to group the data. Lodash is a utility library that provides a set of high-order functions for functional programming.Array.reduce()
method, which applies a function against an accumulator and a series of values in the array.Pros and cons
Here are some pros and cons of each approach:
Lodash (groupBy
):
Pros:
Cons:
Native (Array.reduce()
):
Pros:
Cons:
Other considerations
The benchmark also considers the following factors:
Library: Lodash
Lodash is a popular utility library for JavaScript that provides a set of high-order functions for functional programming. In this benchmark, the groupBy
function is used to group an array by a specified function.
The groupBy
function takes three arguments:
id
property)Special JS feature or syntax
There are no special JavaScript features or syntaxes being tested in this benchmark. However, it's worth noting that some modern browsers and JavaScript engines support new features like async/await, decorators, and other advanced syntaxes.
Overall, the benchmark provides a useful comparison of two approaches for grouping an array of objects, highlighting the trade-offs between using an external library (Lodash) versus implementing the logic natively.