<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>
var data = Array(10000).fill({ filtering: true, mapping: 42 });
data.filter(({ filtering }) => filtering).map(({ mapping }) => mapping)
_(data).filter('filtering').map('mapping').value()
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Native filter-map | |
Lazy Lodash filter-map |
Test name | Executions per second |
---|---|
Native filter-map | 7882.0 Ops/sec |
Lazy Lodash filter-map | 5219.2 Ops/sec |
Let's dive into the world of JavaScript microbenchmarks on MeasureThat.net.
What is tested?
The provided JSON represents two individual test cases for measuring the performance difference between using native JavaScript functions and Lodash, a popular JavaScript utility library, for filtering and mapping arrays. The tests involve creating an array with 10,000 elements, each containing filtering
and mapping
properties, and then filtering out elements based on the filtering
property and mapping the remaining elements to their corresponding mapping
values.
Options compared
There are two approaches being tested:
Array.prototype.filter()
and Array.prototype.map()
) without any external library or helpers.filter
and map
functions, to perform the same filtering and mapping operations.Pros and Cons of each approach
Other considerations
Library description
Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks such as array manipulation, object manipulation, and more. In this context, Lodash's filter
and map
functions are used to filter out elements based on the filtering
property and map the remaining elements to their corresponding mapping
values.
Special JS feature or syntax
None mentioned in the provided code snippets. However, it's worth noting that some JavaScript features like ES6 modules (used by MeasureThat.net) or newer language features might be relevant for more advanced users.
Other alternatives
If you're interested in exploring alternative libraries or approaches, here are a few options:
every
, some
, forEach
) instead of relying on libraries.Keep in mind that the choice of library or approach ultimately depends on your project's requirements, performance needs, and personal preference.