Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash uniq vs Set to unique array
(version: 0)
Comparing performance of:
Set vs Lodash
Created:
4 years ago
by:
Guest
Go to the latest result
HTML Preparation code:
<script src='https://cdn.jsdelivr.net/npm/lodash@4.17.10/lodash.min.js'></script>
Tests:
Set
return [...new Set([1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7])];
Lodash
return _.uniq([1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Set
Lodash
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
3 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36
Browser/OS:
Chrome 147 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Lodash
21.3M/s
Set
8.3M/s
View exact numbers
Test name
Executions per second
✓
Lodash
21,314,148 Ops/sec
Set
8,339,823 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'd be happy to help you understand the benchmark test. **Benchmark Test Overview** The test compares two approaches to remove duplicates from an array: using JavaScript's native `Set` object and using Lodash, a popular utility library for JavaScript. **What is being tested?** In this test, we are measuring the performance of two different functions: 1. A native JavaScript function that uses a `Set` object to remove duplicates from an array. 2. A function from Lodash (version 4.17.10) that uses its own implementation for removing duplicates from an array. **Options being compared** The test compares the performance of these two approaches on large arrays with duplicate elements. The options being compared are: * Native JavaScript `Set` object approach * Lodash's `uniq` function **Pros and Cons of each approach:** 1. **Native JavaScript `Set` object approach:** * Pros: + Lightweight, as it only requires the `Set` object and basic arithmetic operations. + Fast, since `Set` objects are implemented in native code and can take advantage of CPU optimizations. * Cons: + Requires understanding of how `Set` objects work and how to use them correctly. 2. **Lodash's `uniq` function:** * Pros: + Provides a convenient, high-level interface for removing duplicates from an array. + Easy to use, as it doesn't require any special knowledge about sets or arrays. * Cons: + Heavier, since Lodash is a larger library that includes many other utility functions. + May be slower than the native JavaScript approach due to the overhead of function calls and lookups. **Special considerations** In this test, we don't see any special JavaScript features or syntax being used. The `Set` object is a standard feature in modern JavaScript, and Lodash's `uniq` function is designed to work with plain arrays. **Other alternatives** If you wanted to use other approaches for removing duplicates from an array, some examples might include: * Using a regular expression with the `match()` method * Using the `filter()` method with a callback function that checks for duplicates * Using a custom implementation using a hash table or other data structure However, these alternatives may not be as efficient or convenient as the native JavaScript `Set` object approach or Lodash's `uniq` function. I hope this explanation helps! Let me know if you have any further questions.
Related benchmarks
lodash uniq vs native uniq
uniqBy vs stringify performance
lodash uniq vs spread new Set() medium size
Comments
Confirm delete:
Do you really want to delete benchmark?