Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
_.uniq() vs Set() over large array
(version: 2)
Comparing performance of:
lodash uniq vs Set
Created:
7 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.11/lodash.min.js"></script>
Script Preparation code:
var values = _.fill(Array(100000), null).map(() => _.random(0,9));
Tests:
lodash uniq
const results = _.uniq(values);
Set
const results = [...new Set(values)];
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash uniq
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):
Let's break down the benchmark and explain what's being tested, compared, and considered. **What is tested:** The benchmark compares two approaches to remove duplicates from an array: 1. **Lodash `_.uniq()`**: This function removes duplicate values from an array while preserving the original order. 2. **JavaScript `Set` object**: A built-in JavaScript data structure that automatically eliminates duplicate values when used as a collection of unique elements. **Options compared:** The benchmark compares the performance of two approaches: 1. Lodash `_.uniq()` 2. JavaScript `Set` object **Pros and Cons of each approach:** * **Lodash `_.uniq()`**: Pros: + Easy to use and understand, especially for developers familiar with Lodash. + Handles edge cases like preserving the original order. Cons: + Requires an external library (Lodash), which adds overhead. + May not be as efficient as native JavaScript implementation for large datasets. * **JavaScript `Set` object**: Pros: + Native to JavaScript, so no additional library is required. + Efficient for large datasets, as it uses a hash table internally. Cons: + Requires understanding of the `Set` data structure and its behavior. **Library and purpose:** The `_.uniq()` function from Lodash is a utility function that removes duplicate values from an array while preserving the original order. It returns a new array with unique elements, leaving the original array unchanged. **Special JS feature or syntax:** There is no special JavaScript feature or syntax used in this benchmark. **Other alternatives:** For removing duplicates from an array, other alternatives could include: 1. Using `Array.prototype.filter()`: Create a new array with only unique elements by filtering out duplicates. 2. Using `Array.prototype.reduce()`: Reduce the array to a single unique element by accumulating unique values and ignoring duplicates. 3. Manual iteration using a loop: Iterate over the array, keeping track of seen values in an object or Set data structure. However, these alternatives may not be as efficient or elegant as the Lodash `_.uniq()` function or the JavaScript `Set` object for large datasets. In summary, this benchmark compares two popular approaches to remove duplicates from an array: Lodash's `_.uniq()` and the JavaScript `Set` object. The choice of approach depends on trade-offs between ease of use, efficiency, and external library dependencies.
Related benchmarks:
Lodash uniqBy vs Set with Array of object
lodash uniq vs set - 3
lodash uniq vs Array.from(new Set()) vs spread new Set() vs for vs for memory optimized 4
lodash uniq vs Array.from(new Set()) vs spread new Set() [big arrays 2]
Comments
Confirm delete:
Do you really want to delete benchmark?