Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash uniq vs [...new Set()]
(version: 0)
Comparing performance of:
Set vs Array
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdn.jsdelivr.net/npm/lodash@4.17.10/lodash.min.js'></script>
Tests:
Set
var l = [...new Set([1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7])]; return l;
Array
var l = [1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]; return _.uniq(l);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Set
Array
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):
I'd be happy to explain the benchmark and its results. **Benchmark Overview** The provided JSON represents a JavaScript microbenchmarking test created on MeasureThat.net. The test compares two approaches for removing duplicates from an array: using the `Set` object (similar to Python's set data structure) and using the `_uniq` function from the Lodash library. **Options Compared** The benchmark tests two options: 1. **Set**: This approach uses JavaScript's built-in `Set` object to remove duplicates. A `Set` is an unordered collection of unique values, which makes it suitable for removing duplicates. 2. **Array**: This approach uses the `_uniq` function from Lodash (a popular utility library for JavaScript) to remove duplicates. The `_uniq` function takes an array as input and returns a new array with duplicate elements removed. **Pros and Cons of Each Approach** 1. **Set**: * Pros: Efficient, fast, and concise. * Cons: May not be intuitive for developers who are not familiar with the `Set` object. * This approach is useful when you need to remove duplicates from an array and don't care about preserving the original order of elements. 2. **Array**: * Pros: More readable and easier to understand, especially for developers familiar with Lodash. * Cons: May be slower than using a `Set` object, especially for large datasets. **Library Description** The `_uniq` function in Lodash is a utility function that takes an array as input and returns a new array with duplicate elements removed. The function uses the `Set` object under the hood to achieve this. **Special JavaScript Feature/Syntax** This benchmark does not use any special JavaScript features or syntax, making it accessible to developers of various skill levels. **Other Alternatives** If you prefer not to use Lodash or the `Set` object, you could also consider using other approaches to remove duplicates from an array, such as: 1. Using the `filter()` method in combination with the `includes()` method: `array.filter((value, index, self) => self.indexOf(value) === index)`. 2. Using a regular expression with the `replace()` method: `array.replace(/(\w)\1+/g, '$1')`. However, these approaches may be less efficient and more verbose than using a `Set` object or Lodash's `_uniq` function. **Benchmark Results** The latest benchmark results show that: * The `Array` approach (using Lodash's `_uniq` function) has an execution rate of approximately 4.3 executions per second on the specified test machine. * The `Set` approach (using JavaScript's built-in `Set` object) has an execution rate of approximately 8.7 executions per second on the same test machine. These results suggest that using a `Set` object is generally faster and more efficient than relying on Lodash's `_uniq` function for removing duplicates from an array.
Related benchmarks:
lodash uniq vs vanilla set - final
lodash uniq vs native uniq
Lodash uniq vs Set to unique array
Lodash - uniq
lodash uniq vs spread new Set() medium size
Comments
Confirm delete:
Do you really want to delete benchmark?