Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash uniq vs set arossert
(version: 0)
Comparing performance of:
Set vs Array
Created:
2 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);
Array
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
Array
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
Browser/OS:
Chrome 122 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Set
5602410.5 Ops/sec
Array
9182769.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON and explain what is being tested, compared, and their pros and cons. **Benchmark Definition** The benchmark definition provides two test cases: 1. `Set`: This test case creates an array `[1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]` and then returns a new `Set` object from it. 2. `Array`: This test case creates the same array as above and then uses the `_.uniq()` function from Lodash to remove duplicates. **Options Compared** The two options being compared are: 1. **Array**: Using an array and removing duplicates using `_.uniq()` 2. **Set**: Creating a new `Set` object directly from the array **Pros and Cons of Each Approach** * **Array with _.uniq()** + Pros: - This approach is likely to be more efficient since it uses a built-in function that knows how to optimize for this specific use case. - It's also possible that Lodash's implementation is optimized for this particular use case, making it faster than creating an array and then removing duplicates manually. + Cons: - This approach requires Lodash to be included in the benchmark, which may add extra overhead. - The optimization techniques used by _.uniq() might not be directly applicable to a simple `Set` creation. * **Set** + Pros: - Creating a new `Set` object is a more straightforward and efficient approach since it uses the built-in JavaScript API. - It's possible that modern browsers are optimized for creating sets, making this approach faster than using an array with _.uniq(). + Cons: - This approach might be slower if the browser is not optimized for set creation or if there are additional overheads (e.g., due to security restrictions). **Library: Lodash** Lodash is a popular JavaScript library that provides a wide range of functions, including `_.uniq()`. The library's purpose is to provide a collection of high-quality, useful functions that can be used in a variety of contexts. In this benchmark, Lodash is used to remove duplicates from the array. **Special JS Feature or Syntax** There are no special JavaScript features or syntaxes mentioned in this benchmark definition. However, it's worth noting that the use of `Set` objects and the `.uniq()` function might rely on some specific browser implementations or security restrictions. In such cases, the behavior might be different across browsers. **Other Alternatives** If you wanted to compare an alternative approach, here are a few options: * Using a custom implementation for removing duplicates (e.g., using `forEach` and `push`) * Using a library like `fast-set` or `set-objects` instead of Lodash's `_.uniq()` * Comparing the performance of different array data structures (e.g., `ArrayBuffer`, `TypedArray`)
Related benchmarks:
lodash uniq vs native uniq
uniqBy vs stringify performance
lodash uniqBy vs custom uniqBy
uniqBy performance lodash vs native
Lodash uniqBy vs Javascript uniqBy
Comments
Confirm delete:
Do you really want to delete benchmark?