Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
native intersect vs lodash intersect biig
(version: 0)
Comparing performance of:
native big vs lodash big
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.15/lodash.min.js'></script>
Script Preparation code:
function intersect(...array) { const sets = array.map(a => new Set(a)); const s0 = sets[0]; for (const item of s0.values()) { for(let i = 1; i < array.length; i++) { const s = sets[i]; if (!s.has(item)) { s0.delete(item); break; } } } return [...s0]; } var a4 = []; var a5 = []; var a6 = []; for (var i = 0; i < 100000; i++) { a4.push(~~(Math.random() * 100)) a5.push(~~(Math.random() * 100)) a6.push(~~(Math.random() * 100)) }
Tests:
native big
intersect(a4, a5, a6);
lodash big
_.intersection(a4, a5, a6);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
native big
lodash big
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):
**Overview of the Benchmark** The provided benchmark measures the performance difference between a native JavaScript implementation and a version using the popular library Lodash's `intersection` function for finding common elements in arrays. **Native Implementation** The native implementation is a custom-written function named `intersect` that takes an array of sets as input. The function first creates a new Set from each array element, then iterates through the values of the first set and checks if they exist in the subsequent sets. If not found, it removes the value from the first set. **Lodash Implementation** The Lodash implementation uses the `intersection` function, which takes an array of arrays as input. This function is part of the Lodash library and provides a convenient way to find common elements between multiple arrays. **Comparison Options** Two options are being compared: 1. **Native Implementation**: The custom-written native JavaScript function. 2. **Lodash Implementation**: The `intersection` function from the Lodash library. **Pros and Cons of Each Approach** * **Native Implementation**: + Pros: - Customizable implementation, potentially allowing for optimizations specific to the use case. - No dependencies on external libraries. + Cons: - Requires manual set management, which can be error-prone and lead to performance issues if not implemented correctly. - May require additional memory allocation and garbage collection. * **Lodash Implementation**: + Pros: - Widely adopted and well-tested library with a strong community backing. - Provides a convenient and expressive way to find common elements between arrays. + Cons: - Additional dependency on the Lodash library, which may introduce overhead in terms of size and loading time. - May not be optimized for specific use cases or performance profiles. **Library: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks such as array manipulation, string processing, and more. The `intersection` function is part of the Lodash collection and allows users to easily find common elements between multiple arrays. **Special JS Feature/Syntax** None mentioned in the benchmark. **Alternatives** Other alternatives for finding common elements between arrays could include: 1. **Array.prototype.filter()**: While not specifically designed for finding common elements, this method can be used with a callback function to achieve similar results. 2. **Set operations**: Using set data structures and operations (e.g., `set.intersection()` in some libraries) can provide an efficient way to find common elements between arrays. However, these alternatives may not offer the same level of convenience and performance as the native implementation or the Lodash library.
Related benchmarks:
Array Intersection vs. Set Intersection vs. Lodash
native intersect vs lodash intersection 2
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?