Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash Uniq vs Javascript Set (lower iterations)
(version: 0)
Comparing performance of:
Lodash Uniq vs Javascript Set
Created:
7 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<=100000; 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 the provided benchmark definition and test cases. **Benchmark Overview** The goal of this benchmark is to compare the performance of two approaches for removing duplicates from an array: using Lodash's `uniq` function and using JavaScript's built-in `Set` data structure. **Script Preparation Code** The script preparation code creates two identical arrays, `firstEqual` and `secondEqual`, with 100,000 elements each. The purpose of this is to ensure that both the `uniq` function and the `Set` data structure are working with a consistent input set. **Html Preparation Code** The HTML preparation code includes a reference to Lodash's version 4.17.5 library, which provides the `uniq` function used in one of the test cases. **Test Cases** There are two individual test cases: 1. **Lodash Uniq**: This test case measures the performance of the `uniq` function from Lodash, passing in the `arrayToDedup` array as input. 2. **Javascript Set**: This test case measures the performance of creating a new set from the `arrayToDedup` array using JavaScript's built-in `Set` data structure. **Performance Comparison** The benchmark compares the execution speed of both approaches on Firefox 94, running on a Mac OS X 10.15 desktop platform. The results show that: * Lodash Uniq: approximately 88 executions per second * Javascript Set: approximately 82 executions per second This suggests that JavaScript's built-in `Set` data structure is slightly faster than Lodash's `uniq` function for this specific use case. **Pros and Cons** **Lodash Uniq** Pros: * Convenience: Lodash provides a concise and readable way to remove duplicates from an array. * Extensive testing: Lodash has undergone extensive testing, which can provide confidence in its performance. Cons: * Overhead: Using a library like Lodash may introduce additional overhead due to the need for function calls and memory allocation. **Javascript Set** Pros: * Lightweight: JavaScript's built-in `Set` data structure is a lightweight and efficient way to remove duplicates from an array. * Native implementation: The implementation of `Set` is native to JavaScript, which can result in better performance than a library-based approach. Cons: * Steeper learning curve: JavaScript developers may need to familiarize themselves with the `Set` API and its nuances. **Other Considerations** * **Scalability**: As the size of the input array increases, the performance difference between these two approaches may become less significant. * **Memory usage**: Lodash's `uniq` function may use more memory than JavaScript's built-in `Set` data structure, especially for large input arrays. **Alternatives** If you're looking for alternative ways to remove duplicates from an array, consider: * Using a library like Moment.js for date manipulation and deduplication. * Implementing a custom solution using a simple algorithm, such as sorting the array and iterating through it to identify unique elements.
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 uniq vs deconstructed set
lodash uniq vs Array.from(new Set()) vs spread new Set() vs for vs for memory optimized 4
Comments
Confirm delete:
Do you really want to delete benchmark?