Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
native intersect vs lodash intersect small and large 2
(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 s = new Set(array[0]); for (const item of s.values()) { for(let i = 1; i < array.length; i++) { const a = array[i]; if (!a.includes(item)) { s.delete(item); break; } } } return [...s]; } 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 microbenchmarks and explore what's being tested on MeasureThat.net. **Benchmark Definition** The benchmark definition is represented by two sets of code: `Script Preparation Code` and `Html Preparation Code`. The former defines a custom intersection function, `intersect`, which takes an array of arrays as input. The latter includes the URL of the Lodash library, which provides a pre-existing implementation of the `intersection` function. **Test Cases** There are four test cases, each with a different scenario: 1. **Native small**: Tests the custom `intersect` function on two smaller arrays (`a1`, `a2`, and `a3`) containing 10 random integers. 2. **Lodash small**: Tests the Lodash `intersection` function on the same two arrays as above. 3. **Native big**: Tests the custom `intersect` function on two larger arrays (`a4`, `a5`, and `a6`) containing 1000 random integers. 4. **Lodash big**: Tests the Lodash `intersection` function on the same two arrays as above. **Options Compared** In this benchmark, two options are being compared: * Native implementation: The custom `intersect` function defined in the `Script Preparation Code`. * Lodash implementation: The pre-existing `intersection` function provided by the Lodash library included in the `Html Preparation Code`. **Pros and Cons of Each Approach** **Native Implementation (Custom `intersect` Function)** Pros: * Control over the implementation details, which can lead to more efficient code. * No external dependencies, reducing the risk of compatibility issues. Cons: * Requires manual implementation of the intersection algorithm, which can be error-prone and time-consuming. * May not be optimized for performance or scalability. **Lodash Implementation** Pros: * Provides a pre-existing, well-tested, and optimized implementation of the intersection function. * Reduces development time and effort. Cons: * Includes an external dependency, Lodash, which may introduce compatibility issues. * May not be suitable for very large datasets due to memory constraints. **Other Considerations** * Memory usage: The native implementation uses a `Set` data structure to store the intersection results, which can lead to higher memory usage compared to the Lodash implementation, which uses a more efficient algorithm. * Performance: The benchmark results suggest that the native implementation outperforms the Lodash implementation for smaller datasets, but the opposite is true for larger datasets. **Library - Lodash** Lodash is a popular JavaScript library that provides a wide range of utility functions, including `intersection`. It's designed to be lightweight and efficient, making it suitable for use in performance-critical applications. However, it also includes some external dependencies, which may not be desirable in all cases. **Special JS Feature - ES6 Sets** The custom `intersect` function uses ES6 sets (`Set`) to store the intersection results. This feature is available in modern JavaScript engines and provides a convenient way to perform set operations. In summary, this benchmark compares the performance of two approaches: a native implementation using a custom `intersect` function and an Lodash implementation using the pre-existing `intersection` function. The results suggest that the native implementation outperforms the Lodash implementation for smaller datasets, but the opposite is true for larger datasets.
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 3
Comments
Confirm delete:
Do you really want to delete benchmark?