Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
intersectionWith vs find in find vs set big
(version: 0)
Comparing performance of:
intersectionWith vs find in find vs set
Created:
3 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 = Array.from({length: 10000}, (_, i) => [i]) var b = Array.from({length: 30}, (_, i) => [i * 5 + 99950])
Tests:
intersectionWith
!!_.intersectionWith(a, b, (a, b) => a[0] === b[0]).length
find in find
a.find(aIt => b.find(bIt => a[0] === b[0]))
set
const set = new Set(b) a.find(it => set.has(it[0]))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
intersectionWith
find in find
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):
**Benchmark Overview** The provided JSON represents a JavaScript microbenchmark test case on the MeasureThat.net website. The benchmark measures the performance of three different approaches for finding intersection between two arrays: `intersectionWith`, `find in find`, and `set`. **Approaches Compared** 1. **`intersectionWith`**: This approach uses the `lodash.intersectionWith` function, which returns an array containing only the elements that are common to both input arrays. The callback function is used to define a custom comparison logic. 2. **`find in find`**: This approach uses the `Array.prototype.find()` method twice: first on array `a` and then on the result of the inner `find()` call, which is filtered to match elements in array `b`. 3. **`set`**: This approach creates a new Set object from array `b` and then uses the `Array.prototype.find()` method on array `a`, filtering it to match elements present in the set. **Pros and Cons of Each Approach** 1. **`intersectionWith`**: * Pros: Efficient use of built-in functions, potentially faster due to optimized implementation. * Cons: Requires Lodash library, which may introduce overhead for some browsers or environments. 2. **`find in find`**: * Pros: No external dependencies, uses native methods, and can be more readable for some developers. * Cons: May be slower than `intersectionWith` due to the additional function calls and iterations. 3. **`set`**: * Pros: Uses native Set data structure for efficient lookup, no external dependencies. * Cons: Requires creating a new Set object from array `b`, which can be slow for large arrays. **Other Considerations** * The benchmark uses a relatively small dataset (`a` with 10,000 elements and `b` with 30 elements) to keep execution times manageable. Larger datasets would likely skew the results in favor of the fastest approach. * The `RawUAString`, `Browser`, `DevicePlatform`, and `OperatingSystem` fields provide context for the benchmark results, but are not directly relevant to the performance comparison. **Library Usage** The test uses Lodash's `intersectionWith` function, which is a utility function that helps with array intersection. The purpose of this library is to provide a convenient way to perform common array operations without having to implement them from scratch. If you're interested in understanding more about JavaScript array manipulation or Lodash functions, I can provide additional information!
Related benchmarks:
native intersect vs lodash intersection
lodash intersection vs JS
lodash intersectionWith vs array filtering with includes
intersectionWith vs find in find vs set small
Comments
Confirm delete:
Do you really want to delete benchmark?