Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Small Array Performance with Lodash Uniq vs Native Set
(version: 0)
Comparing performance of:
Set vs Array
Created:
3 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdn.jsdelivr.net/npm/lodash@4.17.10/lodash.min.js'></script>
Script Preparation code:
var a = []; for (var i = 0; i < 80; i++) { a.push(i); } for (var i = 0; i < 80; i++) { a.push(i); }
Tests:
Set
return Array.from(new Set(a).values());
Array
return _.uniq(a);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Set
Array
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):
I'll break down the provided benchmark definition and test cases to explain what's being tested, compared, and their pros and cons. **Benchmark Definition** The benchmark measures the performance of two approaches: 1. Using JavaScript's native `Set` object to remove duplicates from an array. 2. Using Lodash's `uniq` function to remove duplicates from an array. **Native Set Approach** In this approach, a new `Set` object is created from the input array `a`, and then the `values()` method is called on it to get an iterator over its unique values. The resulting values are then returned as an array. Pros: * Native JavaScript code, which can be expected to have better performance due to less overhead. * No external dependencies, making it easier to run the benchmark in isolation. Cons: * May not work for all types of data (e.g., objects or maps) that cannot be converted to a `Set`. * Requires modern JavaScript engines that support the `Set` object. **Lodash Uniq Approach** In this approach, the Lodash library's `uniq` function is used to remove duplicates from the input array `a`. The resulting array with unique values is then returned. Pros: * Easy to use and well-documented library. * Works for most types of data, including objects or maps. Cons: * External dependency on Lodash, which can add overhead when running the benchmark. * May have slower performance compared to native JavaScript code due to the additional function call and execution time. **Library and Purpose** The `lodash` library is a popular utility library that provides various functions for common tasks, such as array manipulation. The `uniq` function in particular is used to remove duplicates from an array while preserving order. **Test Cases** There are two test cases: 1. "Set" - Measures the performance of using JavaScript's native `Set` object. 2. "Array" - Measures the performance of using Lodash's `uniq` function. The test results show that Chrome 102 on Desktop (Windows) performs better for the native Set approach with 208,589 executions per second, while the Lodash Uniq approach has a slower execution rate with 136,761 executions per second.
Related benchmarks:
uniqBy performance lodash vs native
Lodash union vs Native Javascript
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 set spread
Comments
Confirm delete:
Do you really want to delete benchmark?