Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash Uniq vs Javascript Set
(version: 2)
Comparing performance of:
Lodash Uniq vs Javascript Set
Created:
8 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.5/lodash.min.js"></script>
Script Preparation code:
var firstEqual = []; var secondEqual = []; for (var i=0; i<=100000000; 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:
Run details:
(Test run date:
4 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36
Browser/OS:
Chrome 142 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash Uniq
265211856.0 Ops/sec
Javascript Set
65364928.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and analyze what's being tested. **Benchmark Purpose:** The primary goal of this benchmark is to compare the performance of two approaches for removing duplicates from an array: 1. Using the `uniq` function from Lodash, a popular JavaScript utility library. 2. Using the native `Set` data structure in JavaScript. **Options Compared:** * **Lodash Uniq:** The `uniq` function takes an array as input and returns a new array with unique elements, preserving the original order of equal elements. * **Javascript Set:** Creating a new `Set` instance from the array, which automatically removes duplicates by storing each element only once. The resulting set can then be converted back to an array using the spread operator (`[...new Set(arrayToDedup)]`). **Pros and Cons:** * **Lodash Uniq:** + Pros: - Easy to use and familiar for developers. - Preserves the original order of equal elements, which can be important in certain scenarios. + Cons: - Adds an additional dependency on Lodash, which may increase bundle size. - May have overhead due to function call and object creation. * **Javascript Set:** + Pros: - Lightweight and efficient, as it uses native JavaScript data structures. - Fast and scalable for large datasets. + Cons: - Requires understanding of the `Set` data structure and its behavior. - May not preserve the original order of equal elements. **Library:** The benchmark uses Lodash version 4.17.5, which is a popular utility library providing a wide range of functions for tasks like array manipulation, string manipulation, and more. **JavaScript Feature/ Syntax:** There's no special JavaScript feature or syntax being tested in this benchmark. The focus is on comparing the performance of two algorithms implemented by libraries (Lodash) versus native JavaScript built-in methods. **Other Alternatives:** * Other approaches to remove duplicates from an array could include: + Using a custom implementation with a hash table or object to keep track of unique elements. + Utilizing other JavaScript libraries like Array.prototype.reduce() or Array.prototype.filter(). + Leveraging external libraries like Ramda, which provides a wide range of functional programming utilities. Keep in mind that the choice of algorithm and library depends on the specific requirements and constraints of your project.
Related benchmarks:
Lodash Uniq vs Javascript [...new Set()]
Lodash Uniq vs Javascript Set Iterator vs Javascript Set Array.from
Lodash Uniq vs Javascript new Set() (small array)
lodash uniq vs set - 3
lodash uniq vs spread new Set() medium size
Comments
Confirm delete:
Do you really want to delete benchmark?