Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash uniq vs set, big arrays
(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 ll = new Array(100000000).map(e => 2);
Tests:
Set
return new Set(ll);
Array
// var l = [1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]; return _.uniq(ll);
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):
**Benchmark Overview** The MeasureThat.net benchmark compares the performance of two approaches to remove duplicates from an array: using a built-in JavaScript `Set` object and using the Lodash library's `uniq` function. **Options Compared** 1. **JavaScript Set**: The first test case creates a new `Set` instance and passes the large array `ll` as its only argument. This is a native JavaScript way to remove duplicates. 2. **Lodash uniq**: The second test case uses the Lodash library's `uniq` function, which is a utility function for removing duplicate values from an array. **Pros and Cons** 1. **JavaScript Set**: * Pros: Native implementation, no external dependencies, lightweight. * Cons: May not work as expected with certain types of data (e.g., objects) or edge cases (e.g., `NaN` or `undefined` values). 2. **Lodash uniq**: * Pros: Well-tested and widely adopted library, supports various array types and edge cases. * Cons: External dependency, potentially slower due to the overhead of a JavaScript module. **Other Considerations** When choosing between these two approaches, consider the specific requirements of your use case: * If you need to work with large arrays or arrays containing objects, `Set` might be a better choice due to its simplicity and native implementation. * If you need to support more complex scenarios (e.g., handling `NaN` values) or want a well-tested library, Lodash's `uniq` function might be a better option. **Library: Lodash** Lodash is a popular JavaScript utility library that provides various functions for common tasks, such as: * Array manipulation (e.g., `uniq`, `map`, `filter`) * String and number manipulation (e.g., `string.prototype.toLowerCase`, `number.prototype.round`) * Object manipulation (e.g., `object.keys()`, `object.values()`) **Special JavaScript Feature/Syntax** None mentioned in this benchmark.
Related benchmarks:
_.uniq() vs Set() over large array
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 Array.from(new Set()) vs spread new Set() [big arrays 2]
Comments
Confirm delete:
Do you really want to delete benchmark?