Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
2lodash uniq vs set
(version: 0)
Comparing performance of:
Set vs Array vs filter
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);
filter
var l = [1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]; l.filter((e,pos) => { return l.indexOf(e) == pos; }) return l;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Set
Array
filter
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 provided benchmark and explain what's being tested. **Benchmark Overview** The benchmark compares three approaches to remove duplicate values from an array: using `lodash uniq`, using an array filter with custom logic, and using a `Set` data structure. The goal is to determine which approach is the most efficient. **Options Compared** 1. **Lodash `uniq`**: This function removes duplicate values from an array while preserving the original order. 2. **Array Filter with Custom Logic**: This approach uses the `filter()` method to create a new array that excludes duplicate values based on their index in the original array. 3. **Set Data Structure**: A `Set` is used as a data structure to store unique values. **Pros and Cons of Each Approach** 1. **Lodash `uniq`**: * Pros: Simple and efficient, preserves original order. * Cons: Requires an external library (lodash). 2. **Array Filter with Custom Logic**: * Pros: Flexible and easy to implement custom logic for duplicate detection. * Cons: Can be slower than `uniq` due to the overhead of filtering, and may not preserve original order. 3. **Set Data Structure**: * Pros: O(1) lookup time for duplicates, preserves uniqueness without explicit filtering. * Cons: May require additional code to convert values to a format suitable for the Set (e.g., strings), and may not be suitable for arrays with complex data structures. **Library and Special Features** The benchmark uses Lodash 4.17.10 as an external library. The `uniq` function is used to remove duplicates from an array, while the rest of the test case relies on built-in JavaScript functionality. There are no special features or syntax specific to JavaScript being used in this benchmark. **Other Alternatives** If you're interested in exploring alternative approaches, consider: 1. **Using a different library**: Other libraries like underscore.js, Ramda, or even built-in array methods (e.g., `reduce()`) could be used as alternatives. 2. **Implementing your own duplicate removal logic**: You can create custom functions to remove duplicates based on specific criteria, such as by value, index, or other properties. Keep in mind that the performance differences between these approaches may vary depending on the specific use case and dataset. If you're interested in exploring more benchmark results or modifying this benchmark, I'd be happy to help!
Related benchmarks:
lodash uniq vs native uniq
Lodash - uniq
uniqBy performance lodash vs native
Lodash uniqBy vs Javascript uniqBy
lodash uniq vs spread new Set() medium size
Comments
Confirm delete:
Do you really want to delete benchmark?