Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash uniq vs set with uuid
(version: 0)
Comparing performance of:
Set vs Array
Created:
one year 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>
Tests:
Set
var l = new Set(['018f9b56-3bc6-712a-a280-a35fa47365c9','018fa9c1-822f-753c-b5cc-4703acc965d6','018f9b56-3bc6-712a-a280-a35fa47365c9','018fa9c1-822f-753c-b5cc-4703acc965d6','018ff2d3-2f8a-76e4-a83b-2b4e2b60ef7b']); return l;
Array
var l = ['018f9b56-3bc6-712a-a280-a35fa47365c9','018fa9c1-822f-753c-b5cc-4703acc965d6','018f9b56-3bc6-712a-a280-a35fa47365c9','018fa9c1-822f-753c-b5cc-4703acc965d6','018ff2d3-2f8a-76e4-a83b-2b4e2b60ef7b']; return _.uniq(l);
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:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:130.0) Gecko/20100101 Firefox/130.0
Browser/OS:
Firefox 130 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Set
2797869.5 Ops/sec
Array
20193416.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Overview of the Benchmark** The provided benchmark measures the performance difference between using an array and a `lodash` library's `uniq()` function to remove duplicate values from an array. **Options Compared** Two approaches are compared: 1. **Array**: The native JavaScript array data structure is used to store unique values. 2. **Set**: A `lodash` library's `Set` data structure is used to store unique values. **Pros and Cons of Each Approach** **Array:** Pros: * Native JavaScript implementation, which means it's likely to be optimized for performance. * Easy to implement and understand. Cons: * May not be as efficient as a specialized data structure like a Set, especially for large datasets. **Set (using `lodash`):** Pros: * Designed for storing unique values, making it more efficient than an array. * Can handle large datasets without significant performance degradation. Cons: * Requires the use of the `lodash` library, which may add extra overhead. * May have a steeper learning curve due to its specialized nature. **Other Considerations** In addition to these two approaches, other methods could be used to remove duplicates from an array, such as using the `filter()` method or the `reduce()` method. However, these methods are less efficient than using a Set or an array with duplicate removal built-in. **Library Used (Lodash)** `lodash` is a popular JavaScript library that provides a wide range of utility functions for tasks like string manipulation, array and object manipulation, and more. The `uniq()` function in this benchmark uses the `Set` data structure to remove duplicates from an array. **Special JS Feature/Syntax** There is no special JavaScript feature or syntax used in this benchmark. It only relies on standard JavaScript features and the `lodash` library's `Set` implementation. **Benchmark Preparation Code** The provided HTML preparation code includes a script tag that loads the `lodash` library, which makes it available for use in the benchmark. **Alternative Approaches** Other approaches to removing duplicates from an array include: * Using the `filter()` method: `arr.filter((val) => arr.indexOf(val) === arr.lastIndexOf(val))` * Using the `reduce()` method: `arr.reduce((acc, val) => acc.includes(val) ? acc : [...acc, val])` While these methods are possible, they may not be as efficient as using a Set or an array with duplicate removal built-in.
Related benchmarks:
lodash uniq vs vanilla set - final
lodash uniq vs native uniq
uniqBy vs stringify performance
lodash uniqBy vs custom uniqBy
Lodash uniqBy vs Javascript uniqBy
Comments
Confirm delete:
Do you really want to delete benchmark?