Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash uniq vs set and Array.from
(version: 0)
Comparing performance of:
Set vs lodash
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 = Array.from(new Set([1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7])); return l;
lodash
var l = [1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]; return _.uniq(l);
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:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
Browser/OS:
Chrome 127 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Set
2831837.2 Ops/sec
lodash
6366293.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks on MeasureThat.net. The provided JSON represents a benchmark that compares two approaches to achieve the same result: removing duplicates from an array using either the `Array.from()` method with a `Set` or the `_uniq()` function from the Lodash library. **What is tested?** The test cases are designed to measure the performance difference between: 1. Using the `Array.from()` method with a `Set` to remove duplicates: This approach creates a new array by converting an existing array to an array-like object, which is then passed to the `Set` constructor. The resulting set is converted back to an array using `Array.from()`, effectively removing any duplicate elements. 2. Using the `_uniq()` function from Lodash to remove duplicates: This approach leverages a popular utility function in the Lodash library that removes duplicates from an array while preserving the original order. **Options compared** The two approaches offer different trade-offs: 1. **Array.from() with Set**: Pros: * Portable across browsers and platforms. * Can be more memory-efficient, as it avoids creating a new JavaScript object. 2. Cons: * May have performance overhead due to the creation of intermediate objects (e.g., the set). 3. **_uniq()` function from Lodash**: Pros: * Highly optimized for performance. * Often included in modern JavaScript applications. Cons: * Less portable across browsers and platforms, as it relies on a specific library. * May not be suitable for all use cases, especially those requiring strict memory control. **Other considerations** When choosing between these approaches: 1. **Memory usage**: If memory is a concern, using `Array.from()` with a `Set` might be a better choice. 2. **Performance**: For most practical applications, the `_uniq()` function from Lodash should provide sufficient performance. 3. **Code readability and maintainability**: Using a well-known library like Lodash can simplify code, but it may not always be clear to others who are familiar with custom implementations. **Library: Set** The `Set` object in JavaScript is a collection of unique values. It provides a fast and efficient way to remove duplicates from an array by converting the array to a set and then back to an array using `Array.from()`. **Special JS feature or syntax: None mentioned** In this benchmark, no special JavaScript features or syntax are used beyond standard ECMAScript implementations. **Alternative approaches** Other alternatives for removing duplicates from an array include: 1. Using `filter()`: This approach can be slower than the two methods compared, as it requires iterating over each element in the original array. 2. Using a custom implementation with a data structure like a trie or a hash table: These approaches can offer better performance and memory efficiency but require more code and expertise. I hope this explanation helps software engineers understand the nuances of these benchmark results!
Related benchmarks:
lodash uniq vs native uniq
uniqBy vs stringify performance
lodash uniq vs set - 3
Lodash - uniq
lodash uniq vs spread new Set() medium size
Comments
Confirm delete:
Do you really want to delete benchmark?