Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash difference vs ES6 Set (large data set and small)
(version: 0)
Comparing performance of:
_difference small to large vs Set/Filter small to large vs _difference small to small vs Set/Filter small to small
Created:
3 years 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 < 20000; i++) { arr1.push('' + i); } var arr1a = []; for(let i = 2000; i >= 0; i--) { arr1a.push('' + i); } var arr2 = []; for(let i = 499; i >= 0; i--) { arr2.push('' + i); }
Tests:
_difference small to large
const finalArray = _.difference(arr2, arr1)
Set/Filter small to large
const outList = new Set([...arr1]); const finalArray = arr2.filter(value => !outList.has(value));
_difference small to small
const finalArray = _.difference(arr2, arr1a)
Set/Filter small to small
const outList = new Set([...arr1a]); const finalArray = arr2.filter(value => !outList.has(value));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
_difference small to large
Set/Filter small to large
_difference small to small
Set/Filter small to small
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.1:latest
, generated one year ago):
Let's dive into the provided JSON and benchmark preparation code. **What is tested?** The test case compares two different approaches for finding the difference between two arrays: 1. Using the `lodash` library, specifically its `_.difference()` function. 2. Using JavaScript's built-in Set data structure in combination with the `filter()` method. **Options being compared:** * **Lodash (`_difference`)**: This approach uses the `_.difference()` function from the Lodash library to find the elements that are present in one array but not in the other. * **Set + Filter (`Set/Filter`)**: This approach creates a Set from one of the arrays, then uses the `filter()` method on the other array to exclude any elements that are already present in the Set. **Pros and cons of each approach:** * **Lodash (_difference_):** + Pros: - Often faster than the Set + Filter approach for smaller datasets. - Can be more concise code-wise. + Cons: - Requires including an additional library (Lodash) in your project. - May not perform as well with very large datasets or complex data structures. * **Set + Filter (`Set/Filter`):** + Pros: - Provides a clear and efficient way to find the difference between two arrays, even for large datasets. - Does not require an additional library. + Cons: - May be slower than Lodash's `_difference()` function for smaller datasets. **Library:** The test case uses the Lodash library, specifically its `_.difference()` function. Lodash is a popular JavaScript utility library that provides a wide range of useful functions for tasks like array manipulation, string manipulation, and more. **JS feature or syntax:** No special JS features or syntax are used in this test case. **Other alternatives:** If you don't want to use Lodash or the Set + Filter approach, other alternatives could be: * Using a custom implementation with a `Map` data structure (instead of a Set). * Leveraging the `intersection()` method from libraries like Underscore.js (similar to Lodash) or Ramda. * Utilizing specialized libraries for array manipulation and set operations, such as Immutable.js. Keep in mind that each alternative has its own trade-offs and may suit specific use cases better than others.
Related benchmarks:
Lodash difference vs Set & Filter vs Map
lodash difference vs ES6 Set (large set)
lodash difference vs ES6 Set (large data set)
lodash difference vs ES6 Set (small data set)
Array.slice() vs. Spread operator
Comments
Confirm delete:
Do you really want to delete benchmark?