Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash Uniq vs Javascript Set 2
(version: 0)
Comparing performance of:
Lodash Uniq vs Javascript Set
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.5/lodash.min.js"></script>
Script Preparation code:
var firstEqual = []; var secondEqual = []; for (var i=0; i<=100; i++) { firstEqual.push(i); secondEqual.push(i); } var arrayToDedup = [...firstEqual, ...secondEqual];
Tests:
Lodash Uniq
_.uniq(arrayToDedup);
Javascript Set
[...new Set(arrayToDedup)]
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash Uniq
Javascript Set
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):
**Benchmark Overview** MeasureThat.net provides a platform for users to create and run JavaScript microbenchmarks, allowing them to compare the performance of different approaches to solving specific problems. **Test Case 1: Lodash Uniq vs Javascript Set** The test case measures the performance difference between using Lodash's `uniq` function and the native `Set` data structure in JavaScript. **Options Compared** Two options are compared: * **Lodash Uniq**: A utility function from the popular Lodash library that removes duplicate elements from an array while preserving the original order. * **Javascript Set**: The built-in `Set` data structure in JavaScript, which automatically eliminates duplicates and provides fast lookup times. **Pros and Cons of Each Approach** * **Lodash Uniq**: + Pros: Preserves the original order of elements, easier to use for developers familiar with Lodash. + Cons: Adds an external dependency (Lodash library), may have a higher overhead due to function call overhead. * **Javascript Set**: + Pros: Built-in data structure, no external dependencies, fast and efficient. + Cons: Requires creating an instance of `Set`, which can be slower than executing a simple function. **Library: Lodash** Lodash is a popular JavaScript library that provides a collection of reusable functions for various tasks. In this case, the `uniq` function is used to remove duplicates from an array while preserving the original order. **Special JS Feature/ Syntax (none)** There are no special JavaScript features or syntax used in this benchmark. **Other Alternatives** If the test authors were not satisfied with Lodash's `uniq` or wanted more control over the implementation, they could have compared other approaches, such as: * Using an array and manually iterating to remove duplicates. * Using a library like `lodash-es` (a subset of Lodash without the dependency on `lodash.min.js`). * Implementing their own custom solution using JavaScript's built-in data structures. **Benchmark Preparation Code Explanation** The preparation code sets up two identical arrays, `firstEqual` and `secondEqual`, and populates them with values from 0 to 100. This allows both options (Lodash Uniq and Javascript Set) to be tested with the same input data. The execution code calls either `_.uniq(arrayToDedup)` or `[...new Set(arrayToDedup)]` on the prepared array, which removes duplicates while preserving the original order. **Benchmark Result Explanation** The benchmark result shows the performance metrics for each option: * **Javascript Set**: The most efficient approach, with an average of 84,078 executions per second. * **Lodash Uniq**: Slightly slower than Javascript Set, with an average of 105,605 executions per second.
Related benchmarks:
Lodash Uniq vs Javascript Set Iterator vs Javascript Set Array.from
Lodash Uniq vs Javascript new Set() (small array)
lodash uniq vs set - 3
lodash uniq vs deconstructed set
lodash uniq vs spread new Set() medium size
Comments
Confirm delete:
Do you really want to delete benchmark?