Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash Uniq vs Javascript [...new Set()]
(version: 0)
Comparing performance of:
Lodash Uniq vs Javascript Set
Created:
6 years ago
by:
Guest
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<=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:
Run details:
(Test run date:
5 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36
Browser/OS:
Chrome 142 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash Uniq
9.8 Ops/sec
Javascript Set
10.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark. **What is being tested?** The benchmark is comparing two approaches to remove duplicates from an array: 1. **Lodash Uniq**: This uses the `_uniq` function from the Lodash library, which removes duplicate elements from an array while preserving order. 2. **JavaScript Set**: This uses the `Set` data structure in JavaScript, which automatically removes duplicates when adding elements. **Options compared** The benchmark is comparing the performance of two approaches: * **Lodash Uniq**: Uses the `_uniq` function from Lodash to remove duplicates from an array. * **JavaScript Set**: Uses the `Set` data structure to remove duplicates from an array. **Pros and Cons of each approach:** 1. **Lodash Uniq**: * Pros: + Easy to use, as it's a well-established library with a simple API. + Preserves order of elements, which might be important in some cases. * Cons: + Adds an extra dependency (Lodash), which may not be desirable for small projects or those with strict bundle sizes. + May have additional overhead due to the library's implementation details. 2. **JavaScript Set**: * Pros: + No extra dependencies, making it a lightweight solution. + Fast and efficient, as sets are designed to remove duplicates quickly. * Cons: + Requires understanding of set data structures and how they work (which might not be immediately clear for everyone). + May not preserve order of elements. **Library and its purpose** In this benchmark, Lodash is used as a library to provide the `_uniq` function, which removes duplicates from an array. The `Set` data structure is built into JavaScript and is not an external library. **Special JS feature or syntax** The benchmark uses the **spread operator (`...`)**, which is a modern JavaScript feature introduced in ES6 (ECMAScript 2015). It allows for creating new arrays by spreading elements from existing arrays. In this case, it's used to create a new array with all elements from `firstEqual` and `secondEqual`. **Other alternatives** If you don't want to use Lodash or the spread operator, you could consider other approaches: * **Manual loop**: Use a manual loop to iterate through the array and skip duplicates. * **Filter() method**: Use the `filter()` method to remove elements from an array that don't meet a certain condition (in this case, all elements except duplicates). * **Using a custom implementation**: Implement your own duplicate removal logic using JavaScript primitive operations. Keep in mind that these alternatives might not be as efficient or convenient as Lodash Uniq or the JavaScript Set approach.
Related benchmarks:
Lodash Uniq vs Javascript Set Iterator vs Javascript Set Array.from
lodash uniq vs set - 3
lodash uniq vs deconstructed set
Lodash union vs Native Javascript
lodash uniq vs spread new Set() medium size
Comments
Confirm delete:
Do you really want to delete benchmark?