Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash Uniq vs Javascript Set and spread
(version: 0)
Comparing performance of:
Lodash Uniq vs Javascript Set
Created:
5 years 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 firstEqual = []; var secondEqual = []; for (var i=0; i<=1000000; i++) { firstEqual.push(i); secondEqual.push(i); } var arrayToDedup = [...firstEqual, ...secondEqual];
Tests:
Lodash Uniq
_.uniq(arrayToDedup);
Javascript Set
[...new Set(arrayToDedup)]
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash Uniq
Javascript Set
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 what's being tested in this benchmark. The test is comparing two approaches to removing duplicates from an array: using Lodash's `uniq` function and using the `Set` data structure in JavaScript, along with the spread operator (`...`). **Lodash's `uniq` function**: This function takes an array as input and returns a new array containing only unique elements. It uses a combination of sorting, iterating over the array, and checking for duplicates to achieve this. **JavaScript Set**: In recent versions of JavaScript (ES6+), `Set` is a collection of unique values. When you create a `Set` from an array using the spread operator (`[...array]`), it automatically removes duplicates because `Set`s can't contain duplicate elements. This approach uses the hash table-like behavior of `Set`s to efficiently check for uniqueness. **Options being compared**: The benchmark is comparing two options: 1. **Lodash's `uniq` function**: This option relies on Lodash's implementation, which may have overhead from additional functions and data structures. 2. **JavaScript Set with spread operator**: This option leverages the built-in JavaScript features, making it a more lightweight and efficient approach. **Pros and Cons:** * **Lodash's `uniq` function**: + Pros: Easy to use, well-documented, and maintained by a reputable library. + Cons: Adds extra overhead due to Lodash's implementation, which may impact performance in certain scenarios. * **JavaScript Set with spread operator**: + Pros: Lightweight, efficient, and leverages native JavaScript features. + Cons: May require more manual handling of edge cases (e.g., null or undefined values). Other considerations: * The benchmark is running on a Chrome 89 browser, which may have specific optimizations or configurations that affect the results. * The `arrayToDedup` array contains 1 million elements, which is a relatively large input size. This may impact the performance differences between the two options. In general, the JavaScript Set with spread operator approach is likely to be faster and more efficient because it leverages native features and has less overhead compared to Lodash's `uniq` function. As for special JS features or syntax, there are a few notes: * The use of the spread operator (`...`) in the benchmark code is a modern JavaScript feature that was introduced in ES6. * There is no mention of using any other special JavaScript features or syntax in this benchmark.
Related benchmarks:
Lodash Uniq vs Javascript Set spread operation
Lodash Uniq vs Javascript Set Iterator vs Javascript Set Array.from
lodash uniq vs Array.from(new Set()) vs spread new Set() vs for vs for memory optimized 4
lodash uniq vs spread new Set() medium size
lodash uniq vs Array.from(new Set()) vs spread new Set() [big arrays 2]
Comments
Confirm delete:
Do you really want to delete benchmark?