Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
uniq-vs-uniqBy
(version: 0)
Compare different ways of extracting unique items
Comparing performance of:
_.uniq() vs _.uniqBy
Created:
6 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>
Script Preparation code:
var workOrders = _.range(_.random(100)).map(x => ({ assignee: { id: _.random(1, 10), }, }));
Tests:
_.uniq()
_.uniq(workOrders);
_.uniqBy
_.uniqBy(workOrders, 'id');
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
_.uniq()
_.uniqBy
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
6 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36
Browser/OS:
Chrome 141 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
_.uniq()
465008.6 Ops/sec
_.uniqBy
2544986.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript benchmarks! **What is being tested?** The provided JSON represents a benchmark for comparing two approaches to extract unique items from an array: 1. `_.uniq(workOrders)`: This test measures the performance of using the `uniq` function, which removes duplicate elements from an array. 2. `_.uniqBy(workOrders, 'id')`: This test measures the performance of using the `uniqBy` function, which removes duplicate elements based on a specified property (`'id'` in this case). **Options being compared** The two options being compared are: 1. **_.uniq**: Removes duplicates based on the value of each element. 2. **_.uniqBy**: Removes duplicates based on the value of a specific property (in this case, `'id'`). **Pros and Cons:** * `_.uniq`: + Pros: Simple to implement, easy to understand, and works well for most use cases. + Cons: Can be slower than `_.uniqBy` when dealing with large arrays or complex data structures. * `_.uniqBy`: + Pros: Optimized for performance, especially when dealing with large arrays or multiple unique properties. It also provides a way to specify the property to use for uniqueness. + Cons: More complex implementation, may require additional configuration. **Library and its purpose** The Lodash library is being used in this benchmark. Specifically: * `_.uniq` and `_.uniqBy` are two of the many functions provided by Lodash for array manipulation and data processing. **Special JS features or syntax** There are no specific JavaScript features or syntax mentioned in the provided code snippets. However, it's worth noting that some modern browsers may have additional capabilities or security features enabled by default, which could affect benchmark results. **Other alternatives** If you're interested in exploring alternative approaches to uniqueness in JavaScript arrays, here are a few options: * **Set**: You can use the `Set` data structure to remove duplicates. However, this approach is limited by the fact that sets only store unique values and do not preserve the original order. * **Map**: Similar to sets, maps can be used to remove duplicates while preserving the original order. * **Array.prototype.filter()`: You can also use the `filter()` method in combination with a callback function to remove duplicates. However, this approach may have performance implications for large arrays. In summary, the benchmark is comparing two approaches to extract unique items from an array: `_.uniq` and `_.uniqBy`. The `_.uniqBy` function provides a more efficient and flexible way to remove duplicates based on a specified property, while `_.uniq` is a simpler implementation that works well for most use cases.
Related benchmarks:
reduce-vs-uniqBy
reduce-vs-uniqBy_2
reduce-vs-uniqBy 1234
uniq-vs-uniqWith
Comments
Confirm delete:
Do you really want to delete benchmark?