Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash uniq vs set my 2
(version: 0)
Comparing performance of:
Set vs Array
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js'></script>
Script Preparation code:
var myArr = Array.from({ length: 60000 }, () => (Math.floor(Math.random() * 1000)));
Tests:
Set
var l = new Set(myArr); return [...l];
Array
return _.uniq(myArr);
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:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0
Browser/OS:
Chrome 126 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Set
1010.2 Ops/sec
Array
965.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of MeasureThat.net and analyze the provided benchmark. **What is being tested?** The provided benchmark measures the performance difference between two approaches for removing duplicates from an array: 1. Using a `Set` data structure (Benchmark Definition: `var l = new Set(myArr); return [...l];`) 2. Using the `uniq` function from the Lodash library (Benchmark Definition: `return _.uniq(myArr);`) **Options being compared** The benchmark compares two approaches, both of which aim to remove duplicates from an array. The main difference between them is: * `Set`: This approach uses a mutable data structure (`Set`) to store unique values. It iterates over the input array and adds each value to the set. Since sets only allow unique values, this approach automatically removes duplicates. Finally, it returns an array containing all values in the set. * Lodash's `uniq` function: This approach uses a library function that implements a stable sort and then filters out duplicates. **Pros and Cons** 1. `Set` approach: * Pros: + Simple to understand and implement + No additional dependencies required (native JavaScript implementation) * Cons: + Creates an additional object, potentially affecting performance in memory-constrained environments + May be slower due to the overhead of creating a set and iterating over it 2. Lodash's `uniq` function: * Pros: + Provides a stable sort, which can help maintain the original order of elements + Often optimized for performance * Cons: + Requires an external library (Lodash), adding an extra dependency + May be slower due to the overhead of loading the library and executing its functions **Library: Lodash** Lodash is a popular JavaScript utility library that provides various functions for tasks like string manipulation, array and object manipulation, and more. The `uniq` function is one of the many useful utilities provided by Lodash. **Special JS feature or syntax** There are no special JavaScript features or syntax used in this benchmark. Both approaches use standard JavaScript syntax and data structures. **Other alternatives** If you wanted to implement a custom duplicate removal approach without using a library like Lodash, you could consider: * Using an `Array.prototype.filter()` combination with the `includes()` method * Utilizing a hash-based approach, such as using a `Map` or an object with a single key However, these alternatives would likely be less efficient and more verbose than the approaches used in this benchmark. I hope this explanation helps you understand what's being tested on MeasureThat.net!
Related benchmarks:
Lodash uniqBy vs Set 10000
Unique lodash vs vanilla
Create an array with unique values - Javascript Array.reduce/Array.indexOf vs Lodash Uniq
Lodash uniqBy vs Set vs Set spread
lodash uniq vs Array.from(new Set()) vs spread new Set() [big arrays 2]
Comments
Confirm delete:
Do you really want to delete benchmark?