Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash vs. Set Intersection
(version: 0)
Comparing performance of:
Javascript Set intersection vs Lodash intersection
Created:
7 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 Set intersection
const firstSet = new Set(first); const secondSet = new Set(second); new Set([...firstSet].filter(item => secondSet.has(item)));
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 Set intersection
Lodash intersection
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36
Browser/OS:
Chrome 145 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Javascript Set intersection
5443873.5 Ops/sec
Lodash intersection
6127008.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the explanation of the benchmark. **What is being tested?** The provided JSON represents two test cases for comparing the performance of two approaches to find the intersection of two arrays: 1. **Native JavaScript Set Intersection**: The first test case uses native JavaScript Sets to perform the set intersection. 2. **Lodash Set Intersection**: The second test case uses the `intersection` function from the Lodash library. **Options being compared** The benchmark is comparing the performance of these two approaches on a sample input: * `first`: `[1, 3, 4, 5, 7]` * `second`: `[2, 3, 5, 6]` The options being compared are: * Native JavaScript Set Intersection * Lodash Set Intersection **Pros and Cons of each approach:** * **Native JavaScript Set Intersection**: + Pros: - Fast and efficient, as Sets use a hash table-based data structure. - Minimal overhead, as Sets only require creating an object with the elements. + Cons: - Requires using native JavaScript features (Sets), which might not be familiar to all developers. - May not perform well in older browsers or environments that don't support modern JavaScript features. * **Lodash Set Intersection**: + Pros: - Easier to use, as it's a library function that abstracts away the native implementation. - More recognizable and familiar to many developers who have worked with Lodash before. + Cons: - May introduce additional overhead due to the abstraction layer. - Requires including an external library (Lodash), which may not be desirable in all situations. **Library and its purpose** In this benchmark, the `lodash` library is used to provide a convenient way to perform set intersection operations. Lodash is a popular JavaScript utility library that provides various functions for common tasks, such as array manipulation, string manipulation, and more. The `intersection` function from Lodash takes two arrays as input and returns an array containing only the elements that are present in both input arrays. **Special JS feature or syntax** There are no special JavaScript features or syntax used in this benchmark. The test cases only use standard JavaScript syntax and features. **Other alternatives** If you're looking for alternative approaches to set intersection, some other options include: * Using a custom implementation with an array-based approach * Using a library like `array-intersection` (a lightweight library specifically designed for array intersections) * Using a third-party library like `fast-set`, which is optimized for performance and provides a more efficient way to perform set operations. Keep in mind that the choice of approach depends on your specific use case, performance requirements, and personal preferences.
Related benchmarks:
Array Intersection vs. Set Intersection vs. Lodash
native intersect vs lodash intersection
custom Set vs Lodash vs custom Array intersection (v3)
Array Intersection vs. Set Intersection vs. Lodash - big
Array Intersection vs. Set Intersection vs. Lodash part 5
Comments
Confirm delete:
Do you really want to delete benchmark?