Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash vs. Set Intersection bad test
(version: 0)
Comparing performance of:
Javascript Set intersection vs Lodash intersection
Created:
6 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 first = []; var second = []; for(var i = 0; i < 10000; i++) { first.push(i); second.push(10000-i); }
Tests:
Javascript Set intersection
const firstSet = new Set(first); const secondSet = new Set(second); new Set([...firstSet].filter(item => secondSet.has(item)));
Lodash intersection
_.intersection(first, second)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Javascript Set intersection
Lodash intersection
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 break down what is being tested in this benchmark. **Script Preparation Code** The script preparation code creates two arrays, `first` and `second`, each with 10,000 elements. The first array contains numbers from 0 to 9,999, while the second array contains the negative counterpart of each number in the first array (e.g., 10000-1 = -9999). This setup is likely intended to simulate a scenario where you need to find common elements between two sets. **Html Preparation Code** The HTML preparation code includes a reference to the Lodash library, specifically version 4.17.5. Lodash is a popular utility library for JavaScript that provides various functions for tasks like string manipulation, array operations, and more. **Individual Test Cases** There are two test cases: 1. **JavaScript Set Intersection**: This test case creates two sets, `firstSet` and `secondSet`, from the prepared arrays and then uses the `Set.prototype.filter()` method to find common elements between them. 2. **Lodash Intersection**: This test case uses the Lodash library's `_.intersection()` function to find common elements between the two input arrays. **Pros and Cons** Let's examine the pros and cons of each approach: * **JavaScript Set Intersection (native)**: + Pros: Native JavaScript sets are generally efficient, and this implementation doesn't rely on external libraries. + Cons: This method requires creating a set from an array and then using `filter()` to find common elements, which can be slower than other approaches. * **Lodash Intersection**: + Pros: Lodash provides optimized implementations for various tasks, including set intersection. This approach is likely to be faster due to the library's optimization. + Cons: This method relies on an external library, which might introduce overhead and dependencies. **Library Usage** The test case uses the Lodash library's `_.intersection()` function, which is a utility function that takes two arrays as input and returns a new array containing only the common elements. The purpose of this function is to simplify set intersection operations. **Special JS Feature/Syntax (if applicable)** There are no special JavaScript features or syntax mentioned in the benchmark code.
Related benchmarks:
Array Intersection vs. Set Intersection vs. Lodash
Array Intersection vs. Set Intersection vs. Lodash part 3
Array Intersection vs. Set Intersection vs. Lodash - big
Array Intersection vs. Set Intersection vs. Lodash part 5
Array Intersection vs. Set Intersection vs. Lodash part 3 mix
Comments
Confirm delete:
Do you really want to delete benchmark?