Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
New set vs UniqWith v3
(version: 7)
Comparing performance of:
UniqWith vs New Set()
Created:
one year ago
by:
Registered User
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>
Script Preparation code:
var MyArr = Array.from({length: 2000000}, () => ({ password: Math.floor(Math.random() * 40), tier: "NORMAL" })); var myCopy = null;
Tests:
UniqWith
myCopy = _.uniqWith(MyArr);
New Set()
MyArr.filter((obj, index, self) => index === self.findIndex((t) => JSON.stringify(t) === JSON.stringify(obj)) ); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
UniqWith
New Set()
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36
Browser/OS:
Chrome 128 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
UniqWith
5.8 Ops/sec
New Set()
7.1 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON and explain what's being tested. **Benchmark Overview** The benchmark measures the performance of two different approaches to create an array with unique elements: 1. `_.uniqWith` from the Lodash library 2. A custom implementation using the `filter()` method and a callback function that checks for equality between objects **Lodash Library: _.uniqWith** `.uniqWith` is a function in the Lodash library that creates an array of unique values, similar to `_.uniq()`, but provides more flexibility by allowing users to customize the uniqueness check. In this benchmark, it's used with the `_` (lodash) object. **Custom Implementation: New Set()** The custom implementation uses the `filter()` method and a callback function that checks for equality between objects. This approach is similar to the `Set` data structure in JavaScript, but implemented manually. **Options Comparison** There are two approaches being compared: 1. **_.uniqWith**: Uses the Lodash library's `uniqWith` function, which provides a simple and efficient way to create an array of unique values. 2. **New Set()**: Implements a custom solution using `filter()` and a callback function that checks for equality between objects. **Pros and Cons** 1. **_.uniqWith** * Pros: + Easy to use and maintain + Built-in in the Lodash library, so no additional setup required * Cons: + May be slower due to the overhead of a library function call 2. **New Set()** * Pros: + Custom implementation, so no additional dependencies or overhead + Can be optimized for performance using techniques like memoization or caching (not shown in this benchmark) * Cons: + Requires more manual setup and maintenance compared to `_.uniqWith` + May require additional considerations for edge cases or boundary conditions **Other Considerations** When choosing between these two approaches, consider the following: 1. **Performance**: If performance is critical, the custom implementation using `filter()` might be faster due to the lack of overhead from a library function call. 2. **Maintainability**: If maintainability and ease of use are more important, `.uniqWith` might be a better choice due to its simplicity and built-in functionality. 3. **Customization**: If you need to customize the uniqueness check or add additional logic, `_.uniqWith` provides more flexibility through its various options. **Other Alternatives** If you're not using JavaScript, other approaches to create an array of unique values include: 1. Using a `Set` data structure (not applicable in this benchmark since it's implemented manually) 2. Using a library like Moment.js or Underscore.js 3. Implementing a custom solution using a different programming paradigm, such as functional programming. Keep in mind that the specific approach used will depend on your project requirements and constraints.
Related benchmarks:
Lodash uniqBy vs Set
Lodash uniqBy vs Set 10000
Lodash uniqBy vs Set with Array of object
Lodash uniqBy vs Set vs Set spread
New set vs UniqWith
Comments
Confirm delete:
Do you really want to delete benchmark?