Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Array Intersection vs. Set Intersection vs. Lodash part 5
(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); firstSet.filter(item => secondSet.has(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 break down the provided benchmark and explain what's being tested. **Benchmark Overview** The benchmark compares three approaches to find the intersection between two arrays or sets: 1. **JavaScript Array Intersection**: Using the `filter` method on an array. 2. **Lodash Intersection**: Using the `_intersection` function from the Lodash library. 3. **Set Intersection**: Using a built-in Set data structure. **Options Compared** The benchmark compares these three approaches for finding the intersection between two arrays or sets, with varying sizes (100 vs 20 elements). The options are compared in terms of performance (executions per second). **Pros and Cons of Each Approach** 1. **JavaScript Array Intersection**: * Pros: Easy to implement, no additional dependencies required. * Cons: May be slower than other approaches for large datasets due to the overhead of filtering. 2. **Lodash Intersection**: * Pros: Fast and efficient, provides a standardized way to perform set operations. * Cons: Requires an additional dependency (the Lodash library), may not be suitable for small projects or performance-critical code. 3. **Set Intersection**: * Pros: Fastest approach, most memory-efficient, ideal for large datasets. * Cons: May not be suitable for smaller datasets due to the overhead of creating a Set. **Lodash Library** The benchmark uses Lodash version 4.17.5. Lodash is a popular JavaScript utility library that provides a set of functional programming helpers. The `_intersection` function takes two arrays as input and returns an array containing only the elements present in both arrays. **Special JS Features/Syntax** None mentioned in this benchmark, but it's worth noting that some modern JavaScript features like `const` and arrow functions are not explicitly mentioned either. **Other Alternatives** If you need a faster Set intersection implementation, you could consider using a library like Fast-Set or SetInterval. If you prefer to implement the Set intersection from scratch, you can use the `Map` data structure instead of Sets. In summary, this benchmark provides a clear comparison between three approaches for finding intersections between arrays and sets, highlighting the trade-offs between ease of implementation, performance, and dependencies required.
Related benchmarks:
Array Intersection vs. Set Intersection vs. Lodash
Array Intersection vs. Set Intersection vs. Lodash part 3
Array Intersection vs. Set Intersection vs. Lodash - big
Array Intersection vs. Set Intersection vs. Lodash part 3 mix
Comments
Confirm delete:
Do you really want to delete benchmark?