Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash Intersection vs. ES6 set has
(version: 0)
Comparing performance of:
Javascript ES6 set vs Lodash intersection
Created:
5 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 first = [1, 3, 4, 5, 7]; var second = [2, 3, 5, 6];
Tests:
Javascript ES6 set
const uFirst = Array.from(new Set(first)); uFirst.filter(Set.prototype.has, new Set(second));
Lodash intersection
_.intersection(first, second)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Javascript ES6 set
Lodash intersection
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 benchmark and explain what is being tested. **What is being tested?** The benchmark compares two approaches to find the intersection of two arrays: using the `Set` data structure in JavaScript (ES6) and using the `intersection` function from the Lodash library. In the first test case, "Javascript ES6 set", an array `first` is created and converted to a `Set`, which is then used with the `has` method of another `Set` object `second`. The resulting intersection is extracted from the second set using the `filter` method. This approach relies on the fact that sets only contain unique values, allowing for efficient lookup. In the second test case, "Lodash intersection", the same two arrays are passed to the `intersection` function provided by Lodash, which returns a new array containing the common elements between the two input arrays. This approach uses a dedicated library function designed specifically for this purpose. **Options compared** The benchmark compares two options: 1. **ES6 Set**: This option uses the built-in `Set` data structure in JavaScript to find the intersection of two arrays. 2. **Lodash Intersection**: This option uses the `intersection` function from the Lodash library, which is a dedicated utility for finding common elements between arrays. **Pros and Cons** Here are some pros and cons of each approach: **ES6 Set** Pros: * Native support in JavaScript, no additional dependencies * Fast lookup times due to set data structure Cons: * May require additional setup (e.g., converting arrays to sets) * Limited functionality outside of array intersection **Lodash Intersection** Pros: * Convenient and easy-to-use function for finding common elements between arrays * Can be used in a wide range of contexts beyond just array intersection Cons: * Adds an additional dependency (the Lodash library) * May have overhead due to the use of a dedicated utility function **Other considerations** The benchmark does not account for other factors that might affect performance, such as: * Array size and distribution * Platform-specific optimizations or issues * Other libraries or dependencies used in conjunction with Lodash If you were to modify this benchmark to include these additional factors, it would provide a more comprehensive picture of the relative performance of these two approaches. **Library and syntax** The `Set` data structure is a built-in JavaScript feature introduced in ECMAScript 2015 (ES6). It provides an efficient way to store unique values and perform fast lookup operations. No special JS features or syntax are explicitly used in this benchmark.
Related benchmarks:
Lodash Intersection vs. ES6 includes
Lodash Intersection vs. ES6 handle duplicate
Lodash Intersection vs. ES6 handle duplicate with set destructuration
Lodash vs. Set Intersection Simple
Comments
Confirm delete:
Do you really want to delete benchmark?