Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash uniq vs VanillaJS
(version: 0)
Taking only string arrays as input into consideration
Comparing performance of:
lodash way vs VanillaJS Set + spread
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
function getStrings() { const generatedStrings = []; for (let i = 0; i < 1000; i++) { generatedStrings.push( Math.random() .toString(36) .replace(/[^a-z0-9]+/g, '') ); } return generatedStrings; }
Tests:
lodash way
return _.uniq(getStrings());
VanillaJS Set + spread
return [...new Set(getStrings())];
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash way
VanillaJS Set + spread
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 dive into the world of JavaScript microbenchmarks! **Benchmark Definition** The benchmark is designed to compare two approaches for removing duplicates from an array of strings: using Lodash's `uniq` function and using a vanilla JavaScript `Set` combined with the spread operator (`...`). **Options Compared** 1. **Lodash `uniq`**: This function takes an array as input and returns a new array with unique elements, preserving the original order. 2. **VanillaJS `Set + spread`**: This approach creates a new `Set` from the input array using the spread operator (`...`) to convert it into an iterable, and then converts it back into an array using the spread operator again. **Pros and Cons** **Lodash `uniq`:** Pros: * Preserves original order of elements * Returns a new array with unique elements Cons: * Requires Lodash library to be included in the benchmark * May have slower performance due to function call overhead **VanillaJS `Set + spread`:** Pros: * Lightweight and fast, as it only uses built-in JavaScript features * No additional library dependencies required Cons: * Preserves original order of elements is not guaranteed (elements may be re-ordered during set creation) * May have slower performance due to set creation and iteration overhead **Other Considerations** Both approaches can work well for small to medium-sized input arrays, but the vanilla JavaScript approach may start to show performance advantages when dealing with larger inputs. However, if preserving original order is crucial, the Lodash `uniq` approach may be a better choice. **Library: Lodash** Lodash (formerly known as "Underscore.js") is a popular JavaScript utility library that provides a collection of high-order functions for functional programming tasks, such as array manipulation, object transformation, and more. In this benchmark, the `uniq` function from Lodash is used to remove duplicates from an array. **Special JS Feature/Syntax** There are no special JS features or syntaxes being used in this benchmark, other than the use of arrow functions (`=>`) in some parts of the script preparation code.
Related benchmarks:
lodash uniq vs native uniq
uniqBy vs stringify performance
Lodash Uniq vs Javascript Set vs Ramda Strings
lodash uniq vs spread new Set() medium size
Comments
Confirm delete:
Do you really want to delete benchmark?