Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash vs. Set Intersection v2
(version: 0)
Comparing performance of:
Javascript Set intersection vs Lodash intersection
Created:
4 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); [...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 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser/OS:
Chrome 120 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
3110677.5 Ops/sec
Lodash intersection
4256595.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and its options. **What is tested on the provided JSON?** The benchmark measures the performance of two approaches: 1. **JavaScript Set Intersection**: This involves creating two Sets from two arrays, `[1, 3, 4, 5, 7]` and `[2, 3, 5, 6]`, and then finding the intersection of these sets using a filter method. 2. **Lodash Intersection**: This involves using the `intersection()` function from the Lodash library to find the intersection of two arrays. **Options Compared** The benchmark compares the performance of: * JavaScript Set Intersection (using built-in Sets) * Lodash Intersection (using the `intersection()` function from the Lodash library) **Pros and Cons of each approach:** * **JavaScript Set Intersection**: + Pros: - Built-in functionality, no external dependency required - Fast and efficient, especially for large datasets + Cons: - Requires manual handling of sets and filter operations - Might not be as readable or maintainable as other approaches * **Lodash Intersection**: + Pros: - More readable and maintainable than the JavaScript Set Intersection approach - Reduces boilerplate code and improves scalability + Cons: - Requires an external dependency (the Lodash library) - Might be slower due to the overhead of loading the library **Library:** The benchmark uses the Lodash library, which is a popular utility library for JavaScript. The `intersection()` function in Lodash takes two arrays as input and returns a new array containing only the elements that are present in both input arrays. **Special JS feature or syntax:** This benchmark does not use any special JavaScript features or syntax beyond what's built into the language. However, it relies on the presence of sets (a data structure introduced in ECMAScript 2015) to implement the filter operation. **Other alternatives:** If you prefer not to use a library like Lodash, other alternatives for set intersection operations include: * Using a custom implementation of sets and filters * Utilizing third-party libraries like `array-intersection` or `set-intersection` * Employing a more complex data structure like a trie or a suffix tree Keep in mind that each alternative has its own trade-offs in terms of performance, readability, and scalability.
Related benchmarks:
Array Intersection vs. Set Intersection vs. Lodash
native intersect vs lodash intersection
Array Intersection vs. Set Intersection vs. Lodash - big
Array Intersection vs. Set Intersection vs. Lodash part 5
Lodash vs. Set Intersection Simple
Comments
Confirm delete:
Do you really want to delete benchmark?