Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodashuniq
(version: 0)
Comparing performance of:
set vs lodash
Created:
9 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.2/lodash.js"></script>
Script Preparation code:
function getRandomInt(min, max) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min)) + min; } var categories = []; for (var i = 0; i < 1000; i++) { categories[i] = getRandomInt(1,100); }
Tests:
set
var uniqueCategories = [...new Set(categories)];
lodash
var uniqueCategories = _(categories).uniq();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
set
lodash
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 benchmark and explain what is being tested. **Benchmark Overview** The benchmark is designed to measure the performance of two different approaches for removing duplicates from an array: the native JavaScript `Set` object, and the `uniq()` function from the Lodash library. **Options Compared** Two options are compared: 1. **Native JavaScript Set**: This approach uses the built-in `Set` object in JavaScript, which is a collection of unique values. The benchmark creates an array of random integers (`categories`) and then uses the `Set` object to create a new array with no duplicates. 2. **Lodash uniq() function**: This approach uses the `uniq()` function from Lodash, a popular utility library for JavaScript. **Pros and Cons** **Native JavaScript Set** Pros: * Fast and efficient * Built-in to JavaScript, so no additional library is required Cons: * May have performance issues on very large datasets due to the overhead of creating and managing the `Set` object * Does not provide any additional functionality beyond removing duplicates **Lodash uniq() function** Pros: * Convenient and easy-to-use API * Provides a way to remove duplicates while preserving the original order of elements (in this case, it doesn't matter since we're just dealing with integers) Cons: * Requires an additional library (Lodash) to be included * May have performance issues on very large datasets due to the overhead of processing and filtering the array **Library: Lodash** Lodash is a utility library for JavaScript that provides a collection of functional programming helpers, including `uniq()`. The `uniq()` function takes an array as input and returns a new array with no duplicates. **Special JS Feature/Syntax: None** There are no special JavaScript features or syntax used in this benchmark. **Other Alternatives** If you wanted to test other approaches for removing duplicates from an array, some alternatives could include: * Using a custom implementation of a hash table or dictionary * Using a sorting and filtering approach (e.g., sorting the array and then filtering out duplicates) * Using a different library or framework that provides a similar functionality (e.g., `array.prototype.dupe()` in some frameworks) It's worth noting that the performance differences between these approaches may be small for small datasets, but can become significant for very large datasets.
Related benchmarks:
lodashuniq2
Lodash max vs Math.max (lodash 4.7.11)
Labels
ramda lodash sortBy
Comments
Confirm delete:
Do you really want to delete benchmark?