Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Uniq vs set
(version: 0)
Comparing performance of:
Set vs Lodash
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Tests:
Set
a = new Set() a.add(3) a.add(4) a.add(3) a.size
Lodash
a = [] a.push(3) a.push(4) a.push(3) _.uniq(a).length
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Set
Lodash
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. **Benchmark Overview** The benchmark measures the performance of two approaches to remove duplicates from an array: using a `Set` data structure and using the `uniq()` function from the Lodash library. **Options Compared** 1. **Using a Set**: This approach uses a built-in JavaScript `Set` object, which automatically removes duplicates by only storing unique values. 2. **Using Lodash's uniq() function**: This approach uses the `uniq()` function from Lodash, which achieves the same result as using a `Set`, but with additional features like handling null and undefined values. **Pros and Cons** 1. **Using a Set**: * Pros: + Fastest execution time (due to its built-in implementation). + Most memory-efficient. * Cons: + Requires JavaScript's built-in `Set` object, which might not be available in older browsers or environments. 2. **Using Lodash's uniq() function**: * Pros: + More comprehensive handling of edge cases (null and undefined values). + Available in most modern browsers and environments (thanks to the Lodash library). * Cons: + Slightly slower execution time compared to using a `Set`. + Requires an additional library download (Lodash). **Library: Lodash** The `uniq()` function from Lodash is used to remove duplicates from an array. It takes an optional first argument to specify the comparison function, but in this case, it uses the default behavior of removing duplicates based on value equality. **Special JavaScript Features/Syntax** None mentioned in this benchmark. **Other Alternatives** If you don't want to use Lodash or a `Set`, you could implement your own duplicate removal algorithm using a simple array loop. However, keep in mind that this approach would likely be slower and less memory-efficient than the two alternatives discussed above. Here's an example of how you might implement a basic duplicate removal function without Lodash: ```javascript function removeDuplicates(arr) { const result = []; for (const value of arr) { if (!result.includes(value)) { result.push(value); } } return result; } ``` This implementation has the same cons as using Lodash's `uniq()` function, but it gives you more control over the implementation details.
Related benchmarks:
lodash uniq vs native uniq
uniqBy vs stringify performance
get uniq values js
Lodash - uniq
Lodash uniqBy vs Javascript uniqBy
Comments
Confirm delete:
Do you really want to delete benchmark?