Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash intersection vs JS
(version: 0)
Comparing performance of:
Lodash vs JS
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>
Tests:
Lodash
_.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1])
JS
let arrays = [[1, 2, 3], [101, 2, 1, 10], [2, 1]]; arrays.reduce((a, b) => a.filter(c => b.includes(c)));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash
JS
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Browser/OS:
Chrome 130 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash
4044596.8 Ops/sec
JS
22546604.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the provided JSON and explain what's being tested. **Benchmark Definition** The benchmark is comparing two approaches to find common elements between arrays: using the `lodash` library (specifically, the `_.intersection()` function) versus native JavaScript. **Options Compared** * **Lodash**: Using the `_.intersection()` function from the `lodash` library. + Pros: - Convenient and concise way to find intersections between arrays. - Often included in project dependencies as a utility function. + Cons: - Adds an external dependency, potentially slowing down benchmark results due to network latency. - May not be optimized for performance or specific use cases. * **Native JavaScript**: Using the `filter()` and `includes()` methods in conjunction with array iteration. + Pros: - No additional dependencies, which can improve benchmark accuracy by minimizing external factors. - Allows for more control over optimization techniques and caching. **Other Considerations** Both approaches have trade-offs: * **Lodash**: The `_.intersection()` function is optimized for performance but relies on the library itself. If not included in the project, this approach won't work. * **Native JavaScript**: This approach requires manual implementation, which can lead to more room for optimization and caching. **Library (lodash)** `lodash` is a popular utility library for JavaScript that provides a wide range of functions for tasks like array manipulation, string processing, and more. The `_.intersection()` function is designed to find common elements between two arrays while ignoring duplicates. **Special JS Feature/Syntax** None are explicitly mentioned in this benchmark definition. However, the use of `includes()` is a relatively recent addition to JavaScript (introduced in ECMAScript 2019), which allows for more concise array comparisons using the `in` operator or the `includes()` method. **Alternatives** Other alternatives for finding common elements between arrays include: * Using `Set` objects and intersection methods, like `new Set([1, 2, 3]).intersection(new Set([101, 2, 1, 10]))`. * Implementing a custom intersection function using techniques like binary search or hash tables. * Utilizing third-party libraries that provide optimized intersection algorithms. Keep in mind that these alternatives might have different performance characteristics and may not be as convenient to use as `lodash` or native JavaScript methods.
Related benchmarks:
Lodash: difference vs intersection
Array Intersection vs. Set Intersection vs. Lodash
Lodash Intersection vs. ES6 includes
Array Intersection vs. Set Intersection vs. Lodash part 5
Array Intersection vs. Set Intersection vs. Lodash part 3 mix
Comments
Confirm delete:
Do you really want to delete benchmark?