Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash's uniq vs new Set
(version: 0)
Comparing performance of:
Set vs uniq
Created:
5 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 = [1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]; return new Set(l);
uniq
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
uniq
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36
Browser/OS:
Chrome 119 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Set
3380389.2 Ops/sec
uniq
6212914.0 Ops/sec
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 is comparing two approaches to remove duplicates from an array of numbers: using the `Set` data structure in JavaScript and using Lodash's `uniq` function. **What are Set and uniq?** * `Set`: A built-in JavaScript data structure that stores unique values. It's an object that only allows you to add, remove, or check for the existence of its elements without maintaining any particular order. * `uniq`: A utility function from Lodash, a popular JavaScript library for functional programming tasks. `uniq` takes an array as input and returns a new array with duplicate elements removed. **Options Compared** The two options being compared are: 1. **Set**: Using the built-in `Set` data structure to remove duplicates. 2. **uniq**: Using Lodash's `uniq` function to remove duplicates. **Pros and Cons of Each Approach** * **Set**: + Pros: Built-in JavaScript, efficient for small arrays, easy to use. + Cons: Not optimized for large arrays, can be slower than other approaches, may not handle edge cases like null or undefined values. * **uniq**: + Pros: Optimized for performance, handles edge cases like null and undefined values, part of a popular and well-maintained library (Lodash). + Cons: Requires an additional dependency (Lodash), can be slower than other approaches for very large arrays. **Other Considerations** * **Memory Usage**: The `Set` approach typically uses less memory than the `uniq` approach, especially for larger arrays. * **Performance**: The performance difference between the two approaches is relatively small, but the `uniq` approach may have a slight advantage due to its optimization and handling of edge cases. **Library Used** The benchmark uses Lodash (version 4.17.10) as a dependency. Lodash provides many useful functions for tasks like array manipulation, object transformation, and functional programming. **Special JS Feature or Syntax** There is no special JavaScript feature or syntax being tested in this benchmark. The code only uses standard JavaScript features, such as arrays, objects, and the `Set` data structure. **Alternatives** If you're looking for alternative approaches to remove duplicates from an array, some options include: * Using a simple loop with `push` and `indexOf` methods. * Using the `filter()` method to remove elements that are not unique. * Using a library like Ramda or Immutable.js, which provide similar functionality to Lodash.
Related benchmarks:
lodash uniq vs vanilla set - final
lodash uniq vs native uniq
Lodash - uniq
Lodash uniqBy vs Javascript uniqBy
lodash uniq vs spread new Set() medium size
Comments
Confirm delete:
Do you really want to delete benchmark?