Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash uniq vs set dest
(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.15/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:
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
Browser/OS:
Chrome 126 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Set
5679192.5 Ops/sec
Array
9387034.0 Ops/sec
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: using JavaScript's built-in `Set` object and using Lodash's `uniq` function. The benchmark measures the performance of each approach. **Test Cases** There are two test cases: 1. **"Array"`**: This test case uses the JavaScript built-in `Set` object to create a set from an array, which automatically removes duplicates. The resulting set is then converted back to an array using the spread operator (`[...new Set()]`). 2. **"Set"`**: This test case uses Lodash's `uniq` function to remove duplicates from an array. **Options Compared** The two options being compared are: * JavaScript built-in `Set` object * Lodash's `uniq` function **Pros and Cons of Each Approach:** * **JavaScript built-in `Set` object:** + Pros: - Fast and efficient, as it uses a hash table to store elements. - Low memory usage, as only unique elements are stored in the set. + Cons: - Requires JavaScript version 1.8.0 or later (before that, `Set` was not supported). - May require additional processing steps to convert between array and set formats. * **Lodash's `uniq` function:** + Pros: - Widely adopted and well-tested library with a large user base. - Allows for easy use of other Lodash functions, making it a convenient choice for developers already familiar with the library. + Cons: - Adds an additional dependency (Lodash), which may slow down page load times or increase bundle size. - May have performance overhead due to the use of additional libraries and dependencies. **Library Used: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks such as data manipulation, functional programming, and more. In this benchmark, `uniq` is used to remove duplicates from an array. The Lodash version used in the benchmark is 4.17.15. **Special JS Feature or Syntax: None** This benchmark does not use any special JavaScript features or syntax that are specific to a particular browser or version. **Alternative Approaches:** There are other ways to remove duplicates from an array, including: * Using `Array.prototype.filter()`: Create a new array with only the unique elements. * Using `Array.prototype.reduce()`: Iterate over the array and accumulate the unique elements into a new array. * Using `d3.set()`: A function from the D3.js library that removes duplicates from an array. However, these alternatives may have different performance characteristics and use cases compared to the JavaScript built-in `Set` object and Lodash's `uniq` function.
Related benchmarks:
lodash uniq vs vanilla set - final
lodash uniq vs native uniq
uniqBy vs stringify performance
uniqBy performance lodash vs native
Lodash uniqBy vs Javascript uniqBy
Comments
Confirm delete:
Do you really want to delete benchmark?