Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash unique vs Array.from(new Set)
(version: 0)
Comparing performance of:
new Set vs uniq
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:
new 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;
uniq
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
new Set
uniq
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 on MeasureThat.net. **Overview** The provided benchmark is designed to compare two approaches for removing duplicates from an array: using the `Array.from(new Set)` method and using Lodash's `uniq` function. The goal is to determine which approach is faster in terms of execution time. **Options Compared** There are two options being compared: 1. **Array.from(new Set)**: This approach uses the built-in `Set` object in JavaScript, which automatically removes duplicates from an array. It then converts the set back into an array using `Array.from()`. 2. **Lodash's uniq function**: Lodash is a popular JavaScript library that provides various utility functions, including `uniq`. This function takes an array as input and returns a new array with duplicate elements removed. **Pros and Cons** 1. **Array.from(new Set)**: * Pros: Built-in method, efficient, and straightforward to use. * Cons: May not be optimized for performance in certain browsers or environments. 2. **Lodash's uniq function**: * Pros: Can be more flexible and customizable than the built-in method. * Cons: Requires an additional library (Lodash) to be included, which may add overhead. **Library Used** In this benchmark, Lodash is used as a dependency to provide the `uniq` function. Lodash is a popular JavaScript library that provides various utility functions for tasks like string manipulation, data transformation, and more. **Special JS Feature or Syntax** There are no special features or syntax used in this benchmark. The code only uses standard JavaScript syntax. **Other Alternatives** If you're interested in exploring other approaches to remove duplicates from an array, here are a few alternatives: 1. **Using a custom implementation**: You could write your own function to remove duplicates from an array using techniques like sorting and iterating through the array. 2. **Using another library**: Depending on your specific requirements, you might consider using another library that provides a similar functionality to Lodash's `uniq` function. **Benchmark Preparation Code** The benchmark preparation code is empty in this case, which means it doesn't perform any initial setup or teardown before running the benchmark. **Individual Test Cases** There are two test cases: 1. **new Set**: This test case creates an array with duplicate elements and then converts it to a set using `Array.from(new Set)`. It then returns the resulting array. 2. **uniq**: This test case creates an array with duplicate elements and passes it to Lodash's `uniq` function, which returns a new array with duplicates removed. **Latest Benchmark Result** The latest benchmark result shows that Safari 16 on a Mac OS X 10.15.7 system can execute the `uniq` test case approximately 5.3 times faster than the `new Set` test case, with an execution rate of around 2636222 executions per second.
Related benchmarks:
uniqBy vs stringify performance
Unique lodash vs vanilla
Lodash - uniq
Lodash union vs Native Javascript
lodash uniq vs spread new Set() medium size
Comments
Confirm delete:
Do you really want to delete benchmark?