Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash uniq vs set strings
(version: 0)
Comparing performance of:
Set vs Array
Created:
4 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:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested. **Benchmark Overview** The benchmark compares two approaches to remove duplicates from an array of strings: using a built-in JavaScript `Set` data structure or a popular utility library called Lodash's `uniq()` function. **Options Compared** 1. **JavaScript Set**: A native JavaScript data structure that allows you to store unique values. In this case, it's used to create a set of duplicates in the array. 2. **Lodash uniq()**: A function from the Lodash library that removes duplicate elements from an array. **Pros and Cons** * **JavaScript Set**: + Pros: Native implementation, fast and efficient, doesn't require any external dependencies. + Cons: Limited functionality compared to other data structures (e.g., no built-in sorting or indexing). * **Lodash uniq()**: + Pros: Widely used and well-maintained library, provides additional features like array manipulation and utilities. + Cons: External dependency, slightly slower than native JavaScript implementations. **Library: Lodash** Lodash is a popular utility library for JavaScript that provides a wide range of functions and methods for working with arrays, objects, and other data structures. The `uniq()` function is one of its most commonly used features, making it easy to remove duplicate elements from an array. **Test Case Analysis** The test cases compare the execution times of two approaches: 1. Using a JavaScript Set to create duplicates in the array (`Benchmark Definition` starts with `var l = new Set(['...'])`). 2. Using Lodash's `uniq()` function to remove duplicates from the array (`Benchmark Definition` starts with `var l = ['...'`, then returns `_.uniq(l)`). The test results show that: * The JavaScript Set approach is slightly faster (3369517 executions per second) compared to the Lodash `uniq()` function approach (2418055.75 executions per second). **Other Alternatives** If you're interested in exploring other approaches, here are a few options: 1. **Array.prototype.filter()**: You can use the `filter()` method to remove duplicates from an array by creating a new array with only unique elements. 2. **D3 Set**: D3.js is a popular data visualization library that provides a set data structure implementation for JavaScript. 3. **Other libraries**: There are other utility libraries available, such as Ramda or Liskind signatures, that provide functions similar to Lodash's `uniq()`.
Related benchmarks:
lodash uniq vs vanilla set - final
lodash uniq vs native uniq
uniqBy vs stringify performance
Lodash uniqBy vs Javascript uniqBy
lodash uniq vs spread new Set() medium size
Comments
Confirm delete:
Do you really want to delete benchmark?