Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Set x includes x _.uniqBy
(version: 0)
Comparing performance of:
set vs includes vs uniqby
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>
Script Preparation code:
var arr = ["aaa", "bbb", "aaa", "ccc", "bbb"];
Tests:
set
var set = new Set(arr); set.has("aaa");
includes
arr.includes("aaa");
uniqby
_.uniqBy(arr, "aaa");
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
set
includes
uniqby
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one month ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36
Browser/OS:
Chrome 145 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
set
17103572.0 Ops/sec
includes
131102184.0 Ops/sec
uniqby
14312168.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark JSON and explain what's being tested. **Benchmark Overview** The test suite consists of three individual test cases, each measuring the performance of a specific JavaScript operation: 1. `set`: Creating a new Set instance from an array and checking if an element is present in it using the `has()` method. 2. `includes`: Checking if an element is present in an array using the `includes()` method. 3. `uniqBy`: Removing duplicate elements from an array based on a specified property using Lodash's `uniqBy()` function. **Options Compared** The benchmark tests different approaches to achieve the same result: * For `set`, two options are compared: + Creating a new Set instance and checking if an element is present in it (`set.has("aaa";`). + Using the `includes()` method on the original array (`arr.includes("aaa");`). * For `uniqBy`, one option is compared: + Using Lodash's `uniqBy()` function to remove duplicates based on a specified property (`_.uniqBy(arr, "aaa");`). **Pros and Cons of Each Approach** 1. **Set**: + Creating a new Set instance: - Pros: Fast lookup times (O(1)) and efficient for large datasets. - Cons: Requires an additional object creation and potentially more memory usage. + Using `includes()` on the original array: - Pros: More familiar and convenient syntax, no additional object creation required. - Cons: Slower lookup times (O(n)), less efficient for large datasets. 2. **UniqBy**: + Using Lodash's `uniqBy()` function: - Pros: Convenient and concise syntax, handles edge cases well. - Cons: Requires an external library dependency (Lodash), potentially slower than native implementations. **Other Considerations** * For the `set` test case, it's worth noting that some JavaScript engines may optimize the `has()` method to use a similar approach as the `includes()` method when dealing with arrays. However, this optimization is not always guaranteed and can vary between browsers. * The `uniqBy()` function uses a combination of sorting and iterating over the array to remove duplicates. This approach can be effective but might introduce additional overhead due to the sorting step. **Library: Lodash** Lodash is a popular JavaScript library that provides a wide range of utility functions, including the `uniqBy()` function used in this benchmark. The library aims to provide convenient and concise solutions for common programming tasks, often sacrificing performance for ease of use. **Special JS Feature/Syntax** None of the provided test cases employ any special or exotic JavaScript features or syntax. They focus on demonstrating the performance differences between three basic operations: creating a Set instance, using `includes()` on an array, and removing duplicates from an array using Lodash's `uniqBy()` function.
Related benchmarks:
uniqBy vs stringify performance
Lodash - uniq
Lodash - uniq2
lodash uniq vs native uniqoififie3f02i409rfi23k
Lodash uniqBy vs Javascript uniqBy
Comments
Confirm delete:
Do you really want to delete benchmark?