Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
test 319823789172
(version: 0)
Comparing performance of:
Javascript Set intersection vs Lodash intersection vs Javascript Array intersection
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 first = [...Array(100)].map(it => ~~(Math.random() * 1000)); var second = [...Array(20)].map(it => ~~(Math.random() * 1000));
Tests:
Javascript Set intersection
const firstSet = new Set(first); const secondSet = new Set(second); const intersection = new Set() for (item of firstSet) { if (secondSet.has(item)) { intersection.add(item) } }
Lodash intersection
_.intersection(first, second)
Javascript Array intersection
first.filter(it => second.includes(it))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Javascript Set intersection
Lodash intersection
Javascript Array 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 dive into the explanation. **Benchmark Overview** The provided JSON represents a JavaScript microbenchmarking test, where users can compare the performance of different approaches to achieve a specific result. The benchmark tests three different methods for finding the intersection of two sets (arrays): `Set` objects, array filtering using the `includes()` method, and Lodash's `intersection()` function. **Options Compared** The options compared in this benchmark are: 1. **JavaScript Set Intersection**: This approach uses the built-in `Set` object to find the intersection of two arrays. 2. **Lodash Intersection**: This approach uses the Lodash library's `intersection()` function, which is a utility function for calculating intersections between arrays. 3. **JavaScript Array Intersection (filtering)**: This approach uses array filtering with the `includes()` method to find the intersection of two arrays. **Pros and Cons** 1. **JavaScript Set Intersection**: * Pros: + Efficient use of memory, as it only stores unique elements in the set. + Fast execution time, as it relies on the built-in `Set` object's operations. * Cons: + May not be suitable for very large datasets, as it can lead to high memory usage. + Not optimized for specific browser versions or platforms. 2. **Lodash Intersection**: * Pros: + Provides a more consistent and predictable result across different browsers and platforms. + Can handle large datasets efficiently, as Lodash is optimized for performance. * Cons: + Introduces additional overhead due to the use of a library. + May not be suitable for specific edge cases or corner cases. 3. **JavaScript Array Intersection (filtering)**: * Pros: + Simple and intuitive implementation. + Suitable for small to medium-sized datasets. * Cons: + Can lead to high memory usage, as the filtered array is created in memory. + May not be efficient for very large datasets. **Library (Lodash)** Lodash is a popular JavaScript utility library that provides various functions for tasks like array manipulation, string processing, and more. The `intersection()` function is one of its utility functions that calculates the intersection between two arrays. **Special JS Features/Syntax** There are no special JavaScript features or syntax mentioned in this benchmark. **Other Alternatives** If you're looking for alternative approaches to find the intersection of two sets (arrays), some other options include: 1. Using a `Map` object instead of a `Set` object. 2. Utilizing a library like `fast-set` or `set-intersection`, which are optimized for performance and provide more features than the built-in `Set` object. 3. Implementing your own custom intersection algorithm, such as using a hash table or a trie data structure. Keep in mind that these alternatives may have different trade-offs in terms of efficiency, memory usage, and code complexity.
Related benchmarks:
Labels
Array Intersection vs. Set Intersection vs. Lodash part 3
Unique lodash vs vanilla
Lodash, Set, Array comparison
Comments
Confirm delete:
Do you really want to delete benchmark?