Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
native intersect vs lodash intersect small and large
(version: 0)
Comparing performance of:
native small vs lodash small vs 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 m = new Map(); for(const a of array) { for(const item of a) { if (m.has(item)) m.set(item, m.get(item) + 1) else m.set(item, 1); } } return [...m.entries()] .filter(([, v]) => v === array.length) .map(([t]) => t); } var a1 = []; var a2 = []; var a3 = []; for (var i = 0; i < 10; i++) { a1.push(~~(Math.random() * 10)) a2.push(~~(Math.random() * 10)) a3.push(~~(Math.random() * 10)) } var a4 = []; var a5 = []; var a6 = []; for (var i = 0; i < 1000; i++) { a4.push(~~(Math.random() * 100)) a5.push(~~(Math.random() * 100)) a6.push(~~(Math.random() * 100)) }
Tests:
native small
intersect(a1, a2, a3);
lodash small
_.intersection(a1, a2, a3);
native big
intersect(a4, a5, a6);
lodash big
_.intersection(a4, a5, a6);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
native small
lodash small
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):
Let's dive into the world of JavaScript benchmarks! **Benchmark Overview** The provided JSON represents a benchmark test case for comparing the performance of two intersection functions: `intersect` (a custom implementation) and `_.intersection` from the Lodash library. **What is tested?** * The `intersect` function takes an array of arrays as input and returns the intersection of all arrays, i.e., the elements that are common to all arrays. * The `_.intersection` function also takes an array of arrays as input and returns the intersection of all arrays. **Options compared** The benchmark compares two options for implementing the `intersect` function: 1. **Native implementation**: A custom implementation written in JavaScript, using a `Map` data structure to keep track of element frequencies. 2. **Lodash implementation**: The `_.intersection` function from the Lodash library, which is a popular utility library for functional programming. **Pros and Cons** **Native Implementation:** Pros: * Custom implementation allows for fine-grained control over performance optimization techniques. * Can potentially be optimized for specific use cases or platforms. Cons: * Requires manual memory management using `Map`, which can introduce additional overhead. * May not be as performant as native library implementations, especially for large datasets. **Lodash Implementation:** Pros: * Utilizes a well-optimized and maintained library implementation. * Provides a consistent and predictable performance profile across different platforms and use cases. Cons: * Requires an additional dependency (the Lodash library). * May have a slightly higher overhead due to the need to import and initialize the library. **Other Considerations** * **Data size**: The benchmark includes two sets of data: small arrays with 10 elements each, and large arrays with 1000 elements each. This allows for a comparison of performance at different scales. * **Browser and Platform**: The benchmark is run on Chrome 91, running on a Linux desktop platform. This ensures that the results are specific to this particular browser and platform combination. **Libraries Used** The `_.intersection` function from Lodash uses a similar algorithm to the native implementation: 1. It creates an empty map (`Map`) to store element frequencies. 2. It iterates over each array in the input, counting the frequency of each element using the map. 3. Finally, it returns an array of elements that have a count equal to the length of all input arrays. The custom `intersect` implementation uses a similar approach, but with additional overhead due to manual memory management using `Map`. **Special JS Features/Syntax** None mentioned in this benchmark. The code is written in standard JavaScript syntax and does not utilize any special features or syntax. **Alternatives** If you're interested in exploring alternative intersection functions or optimizations, here are a few options: * **Built-in `Array.prototype.filter()`**: While not as performant as the custom implementation or Lodash library, this approach can still provide good performance for smaller datasets. * **`Set` data structure**: Using `Set`s instead of maps could potentially provide better performance and memory efficiency for certain use cases. * **Native JavaScript libraries**: Other native JavaScript libraries, such as `fast-leveldb`, might offer optimized implementations of intersection functions that can outperform the custom implementation or Lodash library.
Related benchmarks:
native intersect vs lodash intersection 2
native intersect vs lodash intersection small and large
native intersect vs lodash intersect small and large 2
native intersect vs lodash intersect small and large 3
Comments
Confirm delete:
Do you really want to delete benchmark?