Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash uniq vs set
(version: 0)
Comparing performance of:
Set vs Array
Created:
7 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 = new Set([1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]); return 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 days ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36
Browser/OS:
Chrome 147 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Set
11761970.0 Ops/sec
Array
33052734.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks. **What is being tested?** The benchmark is comparing the performance of two approaches: using a `Set` data structure and using the `uniq()` function from the Lodash library to remove duplicates from an array. **Options being compared:** * Using a `Set` data structure to store unique elements. * Using the `uniq()` function from Lodash to remove duplicates from an array. **Pros and Cons of each approach:** 1. **Using a Set data structure:** * Pros: + Efficient in terms of time complexity (O(1) for add and has methods). + Can handle large datasets without significant performance degradation. + Cons: + May not be as intuitive to use, especially for those familiar with arrays. + Does not preserve the original order of elements (unless implemented manually). 2. **Using Lodash's uniq() function:** * Pros: + Easy to use and understand, as it's a well-known library function. + Preserves the original order of elements. * Cons: + May have a higher constant factor due to the overhead of the library function. **Library used:** The `uniq()` function is part of the Lodash library. Lodash is a popular JavaScript utility library that provides a collection of functional programming helpers, including data manipulation functions like `uniq()`. The library is widely adopted and well-maintained, making it a great choice for many developers. **Special JS feature or syntax:** There are no special features or syntax used in this benchmark. However, using the `Set` data structure does rely on JavaScript's built-in `Set` object, which was introduced in ECMAScript 2015 (ES6). **Benchmark preparation code and HTML code:** The benchmark preparation code is simple: ```javascript var l = new Set([1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]); return l; ``` The HTML code includes a script tag to load the Lodash library: ```html <script src='https://cdn.jsdelivr.net/npm/lodash@4.17.10/lodash.min.js'></script> ``` **Other alternatives:** If you wanted to implement this benchmark without using a `Set` data structure or the Lodash library, you could use other approaches like: * Using an array and manually removing duplicates by iterating over the elements. * Using a custom implementation of a hash set data structure. * Using other libraries like `array-duplicates` or `uniqby`. However, these alternatives would likely have different performance characteristics and might not be as efficient as using a `Set` data structure or the Lodash library.
Related benchmarks:
lodash uniq vs native uniq
uniqBy vs stringify performance
Lodash - uniq
uniqBy performance lodash vs native
Lodash uniqBy vs Javascript uniqBy
Comments
Confirm delete:
Do you really want to delete benchmark?