Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash uniq vs vanilla set
(version: 0)
Comparing performance of:
Uniq vs Set
Created:
7 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.min.js'></script>
Script Preparation code:
var firstEqual = []; var secondEqual = []; for (var i=0; i<=1000; i++) { firstEqual.push(i); secondEqual.push(i); } var arrayToDedup = [...firstEqual, ...secondEqual];
Tests:
Uniq
_.uniq(arrayToDedup);
Set
[...new Set(arrayToDedup)]
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Uniq
Set
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
5 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
Uniq
19022.8 Ops/sec
Set
17441.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON and explain what's being tested, compared, and some of the pros and cons associated with each approach. **Benchmark Definition** The benchmark is comparing two approaches to remove duplicates from an array: 1. **Lodash `uniq`**: Lodash is a popular JavaScript utility library that provides a wide range of functions for data manipulation, among other things. 2. **Vanilla `Set`**: This is the built-in JavaScript object type used to store unique values. **Script Preparation Code** The script creates two arrays with 1000 elements each and pushes them onto two separate arrays (`firstEqual` and `secondEqual`). Then, it uses the spread operator (`...`) to concatenate these two arrays into a single array (`arrayToDedup`). **Html Preparation Code** A reference to the Lodash library is included in the HTML code using a CDN link. This means that the benchmark will use the Lodash library's implementation of `uniq`. **Individual Test Cases** There are two test cases: 1. **Uniq**: This tests the performance of Lodash's `uniq` function on the prepared array (`arrayToDedup`). 2. **Set**: This tests the performance of using a vanilla `Set` object to remove duplicates from the same prepared array. **Pros and Cons** **Lodash `uniq`:** * Pros: + Familiar syntax for developers familiar with Lodash. + Optimized implementation by Lodash maintainers. * Cons: + Adds additional overhead due to the library's existence and initialization time. + May not be as performant as a purely vanilla JavaScript solution. **Vanilla `Set`:** * Pros: + Lightweight, built-in implementation with minimal overhead. + Fast and efficient for large datasets. * Cons: + Requires manual handling of iteration and conversion to/from array. + May have limitations in edge cases (e.g., NaN values). **Other Considerations** When choosing between these approaches, consider the following: * **Development time**: If you need a quick prototype or proof-of-concept, vanilla `Set` might be faster to implement. For production code, Lodash's well-maintained implementation may be more suitable. * **Readability and maintainability**: If readability and maintainability are crucial for your project, Lodash's `uniq` function might be a better choice due to its familiar syntax. **Alternative Approaches** Other alternatives to consider: * Using a different library or framework (e.g., Immutable.js) that provides similar functionality. * Implementing the `uniq` function manually using JavaScript. * Using a custom solution with a specific optimization technique (e.g., hash-based deduplication). Keep in mind that the choice of approach ultimately depends on your project's requirements, performance needs, and development constraints.
Related benchmarks:
Lodash Uniq vs Javascript Set Iterator vs Javascript Set Array.from
Create an array with unique values - Javascript Array.reduce/Array.indexOf vs Lodash Uniq
lodash uniq vs set - 3
Lodash union vs Native Javascript
lodash uniq vs spread new Set() medium size
Comments
Confirm delete:
Do you really want to delete benchmark?