Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash uniq vs new Set with spread to array
(version: 0)
Comparing performance of:
lodash uniq vs new Set with spread
Created:
one year ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js" integrity="sha512-WFN04846sdKMIP5LKNphMaWzU7YpMyCU245etK3g/2ARYbPK9Ub18eG+ljU96qKRCWh+quCY7yefSmlkQw1ANQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
Tests:
lodash uniq
const array = [1, 2, 3, 4, 5, 4, 3, 1, 6, 7, 7, 4, 8, 9, 2, 3, 4, 5, 1, 9, 5, 7, 2, 1]; return _.uniq(array);
new Set with spread
const array = [1, 2, 3, 4, 5, 4, 3, 1, 6, 7, 7, 4, 8, 9, 2, 3, 4, 5, 1, 9, 5, 7, 2, 1]; return [...new Set(array)];
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash uniq
new Set with spread
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Browser/OS:
Chrome 126 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash uniq
4709911.5 Ops/sec
new Set with spread
2339754.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON and explain what is tested, compared, pros/cons of different approaches, library usage, special JS features or syntax, and other considerations. **Benchmark Definition** The provided benchmark definition consists of two test cases: 1. `lodash uniq`: This test case uses the Lodash library to implement a unique array function. 2. `new Set with spread`: This test case uses a built-in JavaScript feature to create a new Set from an array using the spread operator (`[...new Set(array)]`). **What is tested** These two test cases are designed to compare the performance of two approaches for removing duplicates from an array: 1. Using Lodash's `uniq` function. 2. Creating a new Set from an array using the spread operator. **Options compared** The two options are compared in terms of their execution time, which is measured by the number of executions per second. **Pros/Cons of different approaches** Here's a brief overview of the pros and cons of each approach: 1. **Lodash `uniq` function**: * Pros: Well-tested and optimized implementation, handles edge cases (e.g., null or undefined values). * Cons: Additional library dependency, may have overhead due to indirection. 2. **New Set with spread operator**: * Pros: Lightweight and fast, doesn't require any additional dependencies. * Cons: May not handle edge cases (e.g., null or undefined values), requires modern JavaScript support. **Library usage** The Lodash library is used in the `lodash uniq` test case. The library provides a robust implementation of array utilities, including unique value extraction. **Special JS feature or syntax** None mentioned in this specific benchmark. **Other considerations** When implementing these benchmarks, consider the following: * Edge cases: Both approaches should handle edge cases (e.g., null or undefined values) to ensure accurate results. * Browser support: The spread operator is a modern JavaScript feature and may not work in older browsers. Ensure that the test case accounts for this limitation. * Performance characteristics: Consider the performance characteristics of each approach, including cache misses and branching. **Other alternatives** If you'd like to explore alternative approaches, consider the following: 1. **Using `Array.from()` with a Set**: This approach creates a new array from an existing array using `Array.from()`, which can be combined with a Set to achieve uniqueness. ```javascript return Array.from(new Set(array)); ``` 2. **Implementing a custom unique function**: You could implement your own unique function from scratch, but this would likely require more effort and may not offer significant performance benefits. Keep in mind that these alternatives might introduce additional dependencies or complexity, so it's essential to weigh the trade-offs before exploring them further.
Related benchmarks:
lodash uniq vs native uniq
lodash uniq vs Array.from(new Set()) vs spread new Set() vs array.filter vs radash _bigger
Lodash uniqBy vs Javascript uniqBy
lodash uniq vs spread new Set() medium size
Comments
Confirm delete:
Do you really want to delete benchmark?