Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash.filter vs Native.filter
(version: 0)
Comparing performance of:
Native filter vs Lodash filter by prop vs Lodash filter by function
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/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 by prop
_.filter(data, 'filtering');
Lodash filter by function
_.filter(data, ({ filtering }) => filtering);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Native filter
Lodash filter by prop
Lodash filter by function
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark definition and test cases to understand what's being tested. **What is being tested?** The test measures the performance difference between using Lodash's `filter()` function and the native JavaScript `Array.prototype.filter()` method on an array of 1,000,000 objects. The test case checks how long it takes for each approach to filter out all objects that have a specific property (`filtering`) equal to `true`. **Options compared:** Two approaches are being tested: 1. **Native filter**: Using the built-in JavaScript method `Array.prototype.filter()` without any additional libraries. 2. **Lodash filter by prop and function**: Using Lodash's `filter()` function with two different configurations: * **Filter by prop**: Passing a string literal as the second argument to `filter()`, which is expected to be faster because it's a simple lookup. * **Filter by function**: Passing a function as the second argument to `filter()`, which will dynamically evaluate each element in the array and is likely to be slower. **Pros and cons of each approach:** 1. **Native filter**: * Pros: + No additional library overhead. + Fast and efficient, since it's a built-in method. * Cons: + May require more manual coding effort for complex filtering logic. 2. **Lodash filter by prop**: * Pros: + Faster than filter by function due to the simple lookup. + Still uses Lodash, which may be desirable for certain use cases (e.g., when working with a large dataset). * Cons: + May require additional library overhead. 3. **Lodash filter by function**: * Pros: + More flexible and dynamic filtering logic. * Cons: + Likely to be slower than both native filter and Lodash filter by prop due to the function evaluation. **Library:** The test uses Lodash, a popular JavaScript utility library that provides various functions for tasks like array manipulation, object transformation, and more. In this case, it's being used for its `filter()` function. **Special JS feature or syntax:** None mentioned in the provided benchmark definition. **Other alternatives:** If you were to write similar benchmarks without using Lodash, you could explore other JavaScript libraries like: * Ramda (another popular utility library) * Underscore.js (an older library that provides many of the same functions as Lodash) * Or, if you want to stick with native JavaScript, you could use `Array.prototype.filter()` alone, which would eliminate the need for any additional libraries.
Related benchmarks:
Filter: Lodash vs Native
lodash v native filter
Filter: Lodash 2 vs Native
Filter: Lodash vs Native - same filter
Comments
Confirm delete:
Do you really want to delete benchmark?