Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash#uniq + Native
(version: 0)
Comparing performance of:
_.uniqWith vs Using set vs Using Array#includes
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 list = new Array(10000) for (let i = 0; i < list.length; ++i) { list[i] = { v: Math.ceil(100 * Math.random()) } } function deduplicateWithSet(l) { const s = new Set() return l.filter(v => { if (s.has(v.v)) return false s.add(v.v) return true }) } function deduplicateWithIncludes(l) { const s = [] return l.filter(v => { if (s.includes(v.v)) return false s.push(v.v) return true }) }
Tests:
_.uniqWith
return _.uniqWith(list, (v1, v2) => v1.v === v2.v);
Using set
return deduplicateWithSet(list)
Using Array#includes
return deduplicateWithIncludes(list)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
_.uniqWith
Using set
Using Array#includes
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):
Measuring the performance of JavaScript microbenchmarks is crucial to understand how different approaches and libraries affect execution speed. **Benchmark Overview** The provided JSON represents a benchmark test suite for comparing three different approaches to remove duplicates from an array: 1. **Lodash#uniq**: A popular utility library function `uniqWith` that uses a custom comparison function. 2. **Using set**: A straightforward approach using JavaScript's built-in `Set` object. 3. **Using Array#includes**: Another simple approach using the `includes()` method. **Approach Comparison** Here's a brief overview of each approach, including their pros and cons: 1. **Lodash#uniq** (`_.uniqWith`): * Pros: Efficient use of custom comparison function to eliminate duplicates based on specific properties (in this case, `v.v`). * Cons: Requires importing the Lodash library, adding an extra dependency. * Description: This approach leverages the efficiency of Lodash's implementation, but comes with a small performance overhead due to the library import. 2. **Using set**: * Pros: Fast and lightweight since it uses built-in JavaScript functionality. * Cons: May not be as efficient for large datasets or when dealing with complex comparison functions. * Description: This approach is simple and efficient but may not provide the same level of customization as Lodash's `uniqWith`. 3. **Using Array#includes**: * Pros: Simple to implement and does not require any additional libraries. * Cons: May be slower than using a set or custom comparison function, especially for large datasets. * Description: This approach is easy to understand and implement but may not be the most efficient. **Library Explanation** The provided JSON includes the following library: * Lodash (version 4.17.10): A popular utility library that provides various functions for tasks like data manipulation, string manipulation, and more. In this case, it's used for its `uniqWith` function, which is a variant of the standard `uniq` function. **Other Considerations** When measuring performance, it's essential to consider factors like: * **Dataset size**: Larger datasets may affect performance differences between approaches. * **Device and browser variations**: Mobile devices, different browsers, and operating systems can impact execution speeds due to various reasons such as hardware capabilities, JavaScript engine optimizations, or caching mechanisms. * **Customization and control**: The level of customization required for each approach should be taken into account. For example, Lodash's `uniqWith` allows for a custom comparison function, but also adds an extra dependency. **Alternatives** If you're looking for alternative approaches to remove duplicates from an array, consider: * Using `Array.prototype.filter()` with a custom callback function. * Utilizing libraries like Ramda or Liskov's `uniqBy`. * Implementing your own implementation using bitwise operations (e.g., using a hash table). Keep in mind that the most efficient approach will depend on specific use cases and requirements.
Related benchmarks:
Create an array with unique values - Javascript Array.reduce/Array.indexOf vs Lodash Uniq
Lodash uniq vs Set to unique array
Create an array with unique values - Javascript Array.reduce/Array.indexOf vs Lodash Uniq vs custom fn
lodash uniq vs deconstructed set
lodash uniq vs spread new Set() medium size
Comments
Confirm delete:
Do you really want to delete benchmark?