Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Filter: Lodash vs Native
(version: 0)
Comparing performance of:
Native filter vs Lodash filter
Created:
7 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
data.filter(({ filtering }) => filtering)
Lodash filter
_.filter(data, 'filtering')
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Native filter
Lodash filter
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Browser/OS:
Chrome 134 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Native filter
61.9 Ops/sec
Lodash filter
75.1 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'd be happy to explain the benchmark and its various aspects. **Benchmark Overview** The provided benchmark is designed to compare the performance of native JavaScript filtering with Lodash, a popular JavaScript utility library. The benchmark consists of two test cases: "Native filter" and "Lodash filter". Both tests measure how fast they can filter an array of 1 million objects. **Script Preparation Code** The script preparation code defines a dataset `data` containing 1 million objects with a single property `filtering` set to `true`. This dataset is used for both test cases. The script also includes the Lodash library, which is required for the "Lodash filter" test case. **Benchmark Definition JSON** The benchmark definition JSON specifies two tests: 1. **Native filter**: Tests how fast a native JavaScript function can filter the array using the `filter()` method. 2. **Lodash filter**: Tests how fast the Lodash library's `filter()` function can achieve the same filtering operation on the dataset. **Options Compared** The two test cases are comparing the performance of: * Native JavaScript (using built-in `filter()` method) * Lodash library (using `_.filter()` function) **Pros and Cons** ### Native Filter Pros: * No additional dependencies required * Built-in functionality in JavaScript, so no overhead from loading a separate library * Potentially faster since it doesn't require loading an external library Cons: * May not be as efficient or optimized for large datasets due to its dynamic nature ### Lodash Filter Pros: * Optimized and tested by the authors of Lodash * Might provide better performance on certain types of data due to its internal optimizations * Can handle complex filtering operations more easily than native JavaScript Cons: * Requires loading an additional library, which can introduce overhead * May not be as well-optimized for very large datasets compared to a pure native implementation **Library: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks such as array manipulation, string manipulation, and more. The `filter()` function in Lodash is specifically designed to handle filtering arrays efficiently. In this benchmark, the "Lodash filter" test case uses the `_.filter()` function from Lodash to perform the filtering operation on the dataset. **Other Considerations** * **Device and Browser Variability**: The benchmark results show variations in performance across different browsers (Chrome 129) and devices (Desktop). This highlights the importance of testing multiple scenarios to ensure the benchmark's accuracy. * **Test Case Variability**: By including both native filter and Lodash filter, the benchmark tests different approaches to filtering large datasets. This allows users to compare the relative performance of these two methods. **Alternatives** Other alternatives for filtering arrays in JavaScript include: * Vanilla `filter()` method (similar to Native Filter) * Other libraries like Moment.js or Underscore.js * Custom implementations using imperative loops or other optimization techniques Keep in mind that each approach has its trade-offs, and the best choice depends on specific requirements, performance needs, and personal preferences.
Related benchmarks:
lodash v native filter
Filter: Lodash 2 vs Native
Filter: Lodash vs Native - same filter
Map: Lodash vs Native
Comments
Confirm delete:
Do you really want to delete benchmark?