Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash Uniq vs Javascript Set 10000 items
(version: 0)
Comparing performance of:
Lodash Uniq vs Javascript Set
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash/lodash.min.js"></script>
Script Preparation code:
var firstEqual = []; var secondEqual = []; for (var i=0; i<=10000; 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):
Let's break down the benchmark and its components. **Benchmark Definition** The benchmark is designed to compare two approaches for removing duplicates from an array: Lodash's `uniq` function and JavaScript's built-in `Set` object. **Options Compared** Two options are being compared: 1. **Lodash Uniq**: This uses the `uniq` function from the Lodash library, which removes duplicate elements from an array. 2. **JavaScript Set**: This uses the `Set` object in JavaScript, which automatically removes duplicates when used with arrays. **Pros and Cons** * **Lodash Uniq**: + Pros: Easy to use, well-documented, and widely adopted. + Cons: Adds extra overhead due to the library, may not be suitable for very large datasets. * **JavaScript Set**: + Pros: Native implementation, lightweight, and efficient. + Cons: May require more manual effort to implement correctly, especially for large datasets. **Library and Purpose** The `lodash` library is a popular JavaScript utility belt that provides various functions for tasks like array manipulation, string manipulation, and more. In this case, the `uniq` function is used to remove duplicates from an array. **Special JS Feature or Syntax** None are mentioned in the provided code. However, it's worth noting that some JavaScript versions have had experimental features or syntaxes related to sets, but these were not widely adopted until recent versions of the language. **Other Alternatives** Besides Lodash and JavaScript Set, other alternatives for removing duplicates from an array include: * Using `Array.prototype.filter()` and keeping track of unique elements in an external data structure. * Utilizing a library like `underscore` (similar to Lodash) or `ramda`. * Implementing a custom solution using only built-in JavaScript functions. **Benchmark Preparation Code** The script preparation code generates two arrays with 10,000 elements each. These arrays are then used as input for both benchmark tests. **Individual Test Cases** Each test case runs the specified function on the generated array: 1. **Lodash Uniq**: The `uniq` function from Lodash is called on the combined array (`arrayToDedup`). 2. **JavaScript Set**: A new `Set` object is created from the combined array, and its size (i.e., the number of unique elements) is obtained. **Latest Benchmark Result** The latest benchmark result shows that the JavaScript Set approach outperforms Lodash Uniq in terms of executions per second on a Chrome 89 browser running on Windows.
Related benchmarks:
Lodash Uniq vs Javascript Set Iterator vs Javascript Set Array.from
Create an array with unique values - Javascript Array.reduce/Array.indexOf vs Lodash Uniq
Create an array with unique values - Javascript Array.reduce/Array.indexOf vs Lodash Uniq vs custom fn
lodash uniq vs set - 3
lodash uniq vs spread new Set() medium size
Comments
Confirm delete:
Do you really want to delete benchmark?