Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
CORRECTED: Filter-Map: Lodash vs Native
(version: 0)
Comparing performance of:
Native filter-map vs Lazy Lodash filter-map
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>
Script Preparation code:
var data = Array(1000000).fill({ filtering: true, mapping: 42 });
Tests:
Native filter-map
data.filter(({ filtering }) => filtering).map(({ mapping }) => mapping)
Lazy Lodash filter-map
_(data).filter('filtering').map('mapping').value()
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Native filter-map
Lazy Lodash filter-map
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Browser/OS:
Chrome 133 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Native filter-map
52.7 Ops/sec
Lazy Lodash filter-map
46.4 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what is being tested. **Benchmark Definition** The benchmark is testing two approaches for filtering and mapping data in JavaScript: using native functions versus using the `lodash` library. **Script Preparation Code** The script preparation code creates an array of 1,000,000 objects, each with two properties: `filtering` and `mapping`. This data will be used as input for the benchmark tests. **Html Preparation Code** The HTML preparation code includes a reference to the latest version of the `lodash` library (4.17.4) via a CDN link. This library is being tested against its native implementation. **Test Cases** There are two test cases: 1. **Native filter-map**: This test case uses native JavaScript functions (`filter()` and `map()`) to process the data array. 2. **Lazy Lodash filter-map**: This test case uses the `lodash` library's `filter()` and `map()` functions, but with a lazy evaluation approach. The `_` prefix is used to access the `lodash` namespace. **Libraries and Features** * **Lodash**: A popular JavaScript utility library that provides a comprehensive set of functional programming helpers. + In this benchmark, Lodash's `filter()` and `map()` functions are used with lazy evaluation (`_.filter()`, `_().filter('key')`, etc.). * **Native JavaScript**: The built-in JavaScript language features `filter()` and `map()` functions. **Pros and Cons** **Native filter-map** Pros: * No dependencies on external libraries * Fast execution, as native functions are optimized by the V8 engine Cons: * Requires manual handling of errors and edge cases * May have performance differences due to the V8 engine's optimizations **Lazy Lodash filter-map** Pros: * Easy to use with a familiar API (Lodash) * Can avoid manual error handling and edge case management * Can be more readable, as the code is often more concise Cons: * Requires an external dependency on the `lodash` library * May have performance overhead due to the added complexity of lazy evaluation **Other Considerations** * The benchmark uses a large dataset (1,000,000 objects) to ensure accurate results. * The test cases are designed to measure execution speed and throughput. **Alternatives** If you're interested in exploring other approaches or alternatives for filtering and mapping data in JavaScript, here are some options: * **ES6+**: You can use modern JavaScript features like `Array.prototype.filter()` and `Array.prototype.map()` directly, without relying on external libraries. * **Other utility libraries**: Other popular JavaScript libraries like Ramda, Preact, or Immutable.js offer functional programming helpers that might be relevant for this benchmark. * **Native alternatives**: Depending on the specific use case, you might find native implementations of filtering and mapping functions, such as `Array.prototype.filter()` or `Array.prototype.map()`, to be more suitable.
Related benchmarks:
Filter: Lodash vs Native
lodash v native filter
Filter: Lodash 2 vs Native
Map: Lodash vs Native
Map: Lodash vs Native JS
Comments
Confirm delete:
Do you really want to delete benchmark?