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 => Inc().includes(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 the provided benchmarking data and explain what's being tested, compared, and considered. **What is being tested?** The benchmark tests the performance of two approaches to filter an array: 1. Using the `lodash` library's `filter()` method with a callback function that includes another function (`inc`) returned by `Includes()`. 2. Implementing the filtering logic natively (i.e., without using any external libraries). **Options compared** The two options being compared are: 1. **Lodash native filter with includes**: This approach uses the popular `lodash` library to perform the filtering. The callback function passed to `filter()` uses the `Includes()` method of the `inc` array to determine whether each element in the input array should be included. 2. **Native filter**: This approach requires implementing the filtering logic directly without relying on any external libraries. It uses a similar approach as the Lodash example but is written natively. **Pros and Cons** Here are some pros and cons of each approach: 1. **Lodash native filter with includes** * Pros: + Leverages the optimized performance of the `lodash` library. + Reduces code maintenance, as it's easier to reuse existing functionality from a well-maintained library. * Cons: + Adds external dependency (the `lodash` library). + May introduce overhead due to the need to load and initialize an additional library. 2. **Native filter** * Pros: + No external dependencies, reducing overhead and potential issues with versioning or updates. + Can be more performant since it bypasses any unnecessary library overhead. * Cons: + Requires manual implementation of the filtering logic, which can lead to code duplication or errors. **Library** In this case, the `lodash` library is used for its `filter()` method and `Includes()` function. The purpose of `includes()` is to check whether a value exists within another array. **Special JavaScript feature or syntax** There doesn't appear to be any special JavaScript features or syntax being utilized in these benchmarks. **Other alternatives** If you were considering alternative approaches, some options might include: 1. Using `Array.prototype.filter()`, which would eliminate the need for the `includes()` function and simplify the native filtering logic. 2. Implementing a custom filtering algorithm using bitwise operations or other optimized techniques. 3. Leveraging modern JavaScript features like `Set` or `Map` data structures to improve performance. Keep in mind that these alternatives might have different trade-offs in terms of readability, maintainability, or performance compared to the Lodash native filter with includes and native filter approaches.
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?