Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash difference vs JS filter and includes
(version: 0)
Comparing performance of:
Lodash difference vs JS Filter and includes
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var array1 = ['1', '2', '3', '4'] var array2 = ['2', '4']
Tests:
Lodash difference
filteredArray = _.difference(array1, array2);
JS Filter and includes
filteredArray = array1.filter((arr) => !array2.includes(arr));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash difference
JS Filter and includes
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/136.0.0.0 Safari/537.36
Browser/OS:
Chrome 136 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash difference
5039855.5 Ops/sec
JS Filter and includes
9949557.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON and explain what's being tested. **Benchmark Definition** The benchmark is designed to compare two approaches: using Lodash's `difference` function versus implementing a custom filter with `includes`. The script preparation code sets up two arrays, `array1` and `array2`, which are used as input for the test cases. The purpose of these arrays is not explicitly stated in the provided JSON, but based on the context, it appears to be a simple array comparison. **Test Cases** There are two individual test cases: 1. **Lodash difference**: This test case uses Lodash's `difference` function to calculate the difference between `array1` and `array2`. The resulting filtered array is stored in `filteredArray`. 2. **JS Filter and includes**: This test case manually implements a filter using the `filter` method and an `includes` check to find elements in `array2` that are not present in `array1`. The resulting filtered array is also stored in `filteredArray`. **Comparison** The benchmark compares the performance of these two approaches across different browsers (Chrome 129) on various devices (Desktop). By comparing the executions per second for each test case, the benchmark aims to determine which approach is faster. **Pros and Cons** * **Lodash difference**: + Pros: Easy to implement, concise code. + Cons: Requires Lodash library, may have additional overhead due to dependency. * **JS Filter and includes**: + Pros: No additional dependencies, can be optimized further for performance. + Cons: More verbose code, requires manual implementation of `includes` check. Other considerations: * The benchmark only tests the execution time, not the correctness or memory usage of each approach. * Lodash's `difference` function might have some built-in optimizations that are not present in the manual implementation. **Library: Lodash** Lodash is a popular JavaScript library that provides a wide range of utility functions. In this case, it's used to implement the `difference` function, which calculates the difference between two arrays while preserving the original array structure. The use of Lodash introduces an additional dependency and may affect the performance of the benchmark. **Special JS feature or syntax** None are mentioned in the provided JSON. **Alternatives** If you wanted to write a similar benchmark, you could consider using other JavaScript libraries like `Array.prototype.difference` (available in modern browsers) or implementing the filter manually without relying on Lodash. You could also experiment with different optimization techniques, such as using a caching mechanism for the `includes` check.
Related benchmarks:
Array.prototype.filter vs Lodash filter
Array.prototype.filter vs Lodash without
Array.prototype.filter vs Lodash.without
Array.prototype.filter vs Lodash filter (Even Numbers)
Array.prototype.filter vs Lodash without 2
Comments
Confirm delete:
Do you really want to delete benchmark?