Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash difference (large array) vs Set & Filter
(version: 0)
Comparing performance of:
Lodash vs Set & Filter
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
var arr1 = []; for(let i = 0; i < 400; i++) { arr1.push('' + i); } var arr2 = []; for(let i = 49; i >= 0; i--) { arr2.push('' + i); }
Tests:
Lodash
const notInArr1 = _.difference(arr2, arr1) const notInArr2 = _.difference(arr1, arr2)
Set & Filter
const arr1Set = new Set(); const arr2Set = new Set(); arr1.forEach(value => arr1Set.add(value)); arr2.forEach(value => arr2Set.add(value)); const notInArr1 = arr2.filter(value => !arr1Set.has(value)); const notInArr2 = arr1.filter(value => !arr2Set.has(value));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash
Set & 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/126.0.0.0 Safari/537.36
Browser/OS:
Chrome 126 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash
25509.0 Ops/sec
Set & Filter
114994.1 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmarking JSON and explain what's being tested. **Benchmark Definition** The benchmark measures the performance difference between two approaches: 1. **Lodash**: The first approach uses the popular JavaScript library Lodash to find elements that are not in one array but are present in another. Specifically, it uses the `_.difference` function. 2. **Set & Filter**: The second approach uses native JavaScript features (sets and the `filter()` method) to achieve the same result. **Options compared** In this benchmark, two options are being compared: * Lodash with its `_.difference` function * Set and Filter using native JavaScript features **Pros and Cons of each approach:** 1. **Lodash**: * Pros: + Simplifies the code for finding differences between arrays. + Provides a concise and readable way to solve the problem. + Lodash has been optimized and tested, which can lead to better performance in some cases. * Cons: + Adds an external dependency (Lodash) that needs to be included and loaded. + May introduce additional overhead due to the size of the library and its dependencies. 2. **Set & Filter**: * Pros: + Eliminates the need for an external dependency (Lodash). + Can potentially offer better performance due to native optimization and caching by modern browsers. * Cons: + Requires more manual effort and understanding of JavaScript's set and filter methods. + May result in less readable code compared to Lodash. **Library: Lodash** Lodash is a popular JavaScript utility library that provides various functions for tasks such as array manipulation, object transformation, and functional programming. It's widely used in web development due to its extensive feature set and well-maintained codebase. In this benchmark, Lodash is used to provide a concise way to find differences between arrays. **Special JS feature: None** There are no special JavaScript features or syntaxes being tested in this benchmark. **Other alternatives** If the Set & Filter approach isn't suitable for your use case, other alternatives could include: * Using other array manipulation libraries like Array.prototype.filter() and Set.prototype.has() * Implementing a custom solution using JavaScript's native data structures (e.g., `Map` or `WeakSet`)
Related benchmarks:
Lodash difference vs filtering via set membership with high overlap
Lodash difference vs Set & Filter vs Map
Lodash.filter vs Lodash.without
Array.slice() vs. Spread operator
Array.slice() vs. Spread operator (10000 items)
Comments
Confirm delete:
Do you really want to delete benchmark?