Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash / native filter with _includes
(version: 0)
Comparing performance of:
lodash vs native
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.1/lodash.js"></script>
Script Preparation code:
const inc = [1,2]; const arr = []; for(let i=0; i < 1000; i++){ arr.push({ id: _.random(0, 5) }); } function Arr(){ return arr; } function Inc(){ return inc; }
Tests:
lodash
_.filter(Arr(), elem => _.includes(Inc(), elem.id))
native
Arr().filter(elem => Inc().includes(elem.id))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash
native
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 what's being tested in the provided JSON. **Benchmark Definition** The benchmark is comparing two approaches: 1. **Lodash filtering**: This approach uses the `_.filter()` method from the Lodash library to filter an array of objects based on a condition that checks if an object's `id` property is included in another array (`inc`) using the `_includes()` method. 2. **Native filtering**: This approach does the same thing as Lodash filtering, but without using the Lodash library. Instead, it uses a simple filter function to check if each element's `id` property is included in the `inc` array. **Options Compared** The two approaches are compared in terms of performance, with the goal of determining which one is faster for this specific benchmark. **Pros and Cons** * **Lodash filtering**: + Pros: Lodash provides a convenient and expressive way to perform common operations like filtering and sorting. It also takes care of edge cases and optimization. + Cons: Using an external library can introduce overhead, such as loading time and memory usage. Additionally, the benchmark may be affected by the time it takes to load the Lodash library. * **Native filtering**: + Pros: This approach is lightweight and doesn't rely on any external libraries, which means no additional overhead or dependencies. + Cons: The filter function needs to be implemented manually, which can lead to errors if not done correctly. Additionally, this approach may not be as concise or expressive as Lodash filtering. **Library** In the benchmark definition, Lodash is used in the "Benchmark Definition" section: `const elem = { id: _.random(0, 5) };` Lodash provides a set of functional programming utilities that can be used to simplify and improve the performance of certain operations. In this case, `_filter()` and `_includes()` are used to perform the filtering operation. **Special JS Feature** There is no special JavaScript feature or syntax being tested in this benchmark. The focus is on comparing the performance of two approaches with different libraries (Lodash vs native filtering). **Other Alternatives** If you were to implement a custom filter function for the native approach, you could use a combination of `Array.prototype.includes()` and a callback function to achieve the same result as Lodash's `_includes()` method. For example: ```javascript function includes(arr, elem) { return arr.some(i => i.id === elem); } ``` However, this would not provide the same level of conciseness or expressiveness as Lodash filtering. Overall, the benchmark is designed to help users understand the performance differences between using an external library (Lodash) versus implementing a custom solution (native filtering).
Related benchmarks:
Lodash filter
lodash / native filter with includes
Lodash filter 1 000 000
Array.prototype.filter vs Lodash 4.17.5 filter
Comments
Confirm delete:
Do you really want to delete benchmark?