Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash vs. Set Intersection on pre-existing sets
(version: 0)
Comparing performance of:
Javascript Set intersection vs Lodash intersection array vs Lodash intersection set
Created:
2 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 a = [1, 3, 4, 5, 7]; var b = [2, 3, 5, 6]; var aSet = new Set(a) var bSet = new Set(b)
Tests:
Javascript Set intersection
new Set([...aSet].filter(item => bSet.has(item)));
Lodash intersection array
_.intersection(a, b)
Lodash intersection set
_.intersection(aSet, bSet)
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 array
Lodash intersection set
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's being tested. **Script Preparation Code** The script preparation code creates two arrays, `a` and `b`, and two sets, `aSet` and `bSet`, from these arrays using the `Set` constructor. The purpose of creating these sets is to provide a pre-existing data structure that will be used for testing. **Html Preparation Code** The HTML preparation code includes a reference to Lodash version 4.17.5, which is a popular JavaScript utility library. Lodash provides a set of functions that make it easier to work with arrays, objects, and other data structures. **Benchmark Definition JSON** The benchmark definition JSON contains three test cases: 1. **Javascript Set intersection**: This test case uses the `Set` constructor and the `has` method to perform an intersection on two sets. 2. **Lodash intersection array**: This test case uses the Lodash `intersection` function to find the common elements between two arrays. 3. **Lodash intersection set**: This test case uses the Lodash `intersection` function with sets, similar to the first test case. **Options Compared** The three test cases compare different approaches for performing an intersection on data structures: 1. **Built-in JavaScript Set intersection**: Uses the `Set` constructor and the `has` method. 2. **Lodash intersection array**: Uses the Lodash `intersection` function with arrays. 3. **Lodash intersection set**: Uses the Lodash `intersection` function with sets. **Pros and Cons** Here are some pros and cons of each approach: 1. **Built-in JavaScript Set intersection**: * Pros: Fast, efficient, and widely supported. * Cons: May not be as convenient to use as other libraries like Lodash. 2. **Lodash intersection array**: * Pros: Convenient to use, easy to read, and well-documented. * Cons: Additional dependency on Lodash, may be slower than native JavaScript implementation. 3. **Lodash intersection set**: * Pros: Easy to use, similar syntax to `intersection` with arrays. * Cons: Additional dependency on Lodash, may be slower than native JavaScript implementation. **Other Considerations** When choosing a library like Lodash for your project, consider factors such as: 1. **Dependency size**: Lodash is a large library that includes many utility functions. Depending on the size of your project, you may want to prioritize smaller dependencies. 2. **Learning curve**: If you're not familiar with Lodash, it may take time to learn its API and syntax. 3. **Performance**: While Lodash can be fast, native JavaScript implementations like `Set` can be faster in some cases. **Alternatives** If you don't want to use a library like Lodash, you could consider other alternatives for performing intersections: 1. **Native JavaScript Set intersection**: As mentioned earlier, using the `Set` constructor and the `has` method. 2. **Other utility libraries**: There are many other JavaScript libraries that provide similar functionality to Lodash, such as Ramda or Underscore.js. In summary, the benchmark tests the performance of different approaches for performing intersections on data structures: built-in JavaScript Set intersection, Lodash intersection array, and Lodash intersection set. The results can help you choose the best approach for your specific use case, considering factors like dependency size, learning curve, and performance.
Related benchmarks:
Lodash union vs native Set() implementation
native intersect vs lodash intersection
intersectionWith vs find in find vs set small
lodash union vs native set spread
Comments
Confirm delete:
Do you really want to delete benchmark?