Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash uniq vs Array.from(new Set()) vs spread new Set() with filter
(version: 0)
Comparing performance of:
Spread vs use lodash vs Array.from
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>
Tests:
Spread
return [...new Set(['1','1','2','','','3','4'])].filter(String)
use lodash
return _.uniq(['1','1','2','','','3','4']).filter(String);
Array.from
return Array.from( new Set(['1','1','2','','','3','4']) ).filter(String);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Spread
use lodash
Array.from
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):
**Overview of the Benchmark** The provided JSON represents a JavaScript microbenchmark, where three different approaches are compared to find the most efficient way to remove duplicates from an array while filtering out empty strings. **Approaches Compared** 1. **Spread Operator with New Set and Filter**: This approach uses the spread operator (`...`) to convert the set to an array, followed by filtering out empty strings using the `filter()` method. 2. **Lodash uniq()**: This approach uses the `uniq()` function from the Lodash library, which removes duplicates while preserving order. 3. **Array.from() with Filter**: This approach uses the `Array.from()` method to create a new array from an existing iterable (in this case, a set), followed by filtering out empty strings using the `filter()` method. **Pros and Cons of Each Approach** 1. **Spread Operator with New Set and Filter**: * Pros: Simple, efficient, and does not require any external libraries. * Cons: May be slower than optimized implementations (like Lodash's `uniq()`), especially for large datasets. 2. **Lodash uniq()**: * Pros: Fast and efficient, with a well-optimized implementation that can handle large datasets. * Cons: Requires the Lodash library to be included in the test environment. 3. **Array.from() with Filter**: * Pros: Can be faster than the spread operator approach for large datasets, since it uses an optimized implementation under the hood. * Cons: May have slower startup times due to the creation of a new array from an existing iterable. **Library Usage** The benchmark uses Lodash's `uniq()` function to remove duplicates. The Lodash library is included in the test environment via a script tag (`<script src='https://cdn.jsdelivr.net/npm/lodash@4.17.10/lodash.min.js'></script>`). **Special JavaScript Feature or Syntax** None of the approaches rely on any special JavaScript features or syntax that are not widely supported. **Other Alternatives** For this specific use case, other alternatives could include: * Using a custom implementation with a hash table to keep track of unique elements * Using a different library like `underscore` or `moment.js` * Optimizing the spread operator approach using techniques like memoization or caching However, for most use cases, the approaches compared in this benchmark are sufficient and efficient.
Related benchmarks:
lodash uniq vs Array.from(new Set()) vs spread new Set() vs array.filter
Lodash union vs Native Javascript
lodash uniq vs spread new Set()
lodash uniq vs spread new Set() medium size
Comments
Confirm delete:
Do you really want to delete benchmark?