Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
native intersect vs lodash intersect small and large 3
(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 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 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 benchmarking results and explain what's being tested. **What's being tested?** The benchmark is testing the performance of two different approaches to calculate the intersection of multiple arrays: 1. **Native approach**: The `intersect` function, which uses a simple algorithm to find the common elements between sets. 2. **Lodash approach**: The `_.intersection` function from the Lodash library, which provides a more robust and efficient implementation for calculating intersections. **Options compared** The benchmark is comparing two sets of options: * **Small arrays**: Three small arrays (`a1`, `a2`, `a3`) with 10 elements each. * **Large arrays**: Three large arrays (`a4`, `a5`, `a6`) with 1000 elements each. **Pros and cons** Here are the pros and cons of each approach: **Native approach** Pros: * Lightweight and simple to implement * Low memory overhead Cons: * Can be slow for large datasets due to the use of loops and set operations * May not be optimized for performance **Lodash approach** Pros: * More efficient and optimized for performance * Provides a robust implementation that handles edge cases well Cons: * Adds an external dependency (the Lodash library) * May have higher memory overhead due to the creation of intermediate data structures **Library: Lodash** The `_.intersection` function from Lodash is a popular and widely-used implementation for calculating intersections. It uses a combination of algorithms and data structures to efficiently find common elements between arrays. **Special JS feature or syntax** This benchmark does not use any special JavaScript features or syntax that are unique to modern browsers. The code is written in vanilla JavaScript, making it easy to understand and maintain. **Other alternatives** If you're interested in exploring alternative implementations for calculating intersections, here are a few options: * **Array.prototype.filter()**: You can use `filter()` to create an array with only the common elements between two arrays. * **Set intersection**: You can use the `Set` data structure to find the intersection of two arrays by creating sets from each array and then finding their intersection using `Set.prototype.intersection()`. * **Native Web Workers**: If you're dealing with very large datasets, you can consider using Web Workers to parallelize the computation and improve performance. Keep in mind that these alternatives may not be as efficient or optimized as the Lodash implementation, but they can still provide a good starting point for exploration.
Related benchmarks:
native intersect vs lodash intersection 2
native intersect vs lodash intersection small and large
native intersect vs lodash intersect small and large
native intersect vs lodash intersect small and large 2
Comments
Confirm delete:
Do you really want to delete benchmark?