Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash uniq vs set to array
(version: 0)
Comparing performance of:
Set vs Array
Created:
6 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:
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;
Array
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
Array
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.1:latest
, generated one year ago):
Let's break down the provided JSON and benchmark preparation code. **Benchmark Name**: "lodash uniq vs set to array" This test compares two approaches for removing duplicates from an array: 1. Using the `Set` data structure (ES6 feature) to create a unique array (`Array.from(new Set(...))`) 2. Using the Lodash library's `uniq` function **Individual Test Cases**: We have two test cases: ### Test Case 1: "Set" This test uses the `Set` data structure to create an array of unique values. * The benchmark definition code creates a `Set` from the array `[1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]` * It then uses `Array.from()` to convert the `Set` back into an array * The result is returned for evaluation ### Test Case 2: "Array" This test uses Lodash's `uniq` function to remove duplicates from an array. * The benchmark definition code creates an array `[1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]` * It then calls the Lodash `uniq` function on this array * The result is returned for evaluation **Library Used**: In the "Array" test case, we use Lodash's `uniq` function. Lodash is a popular JavaScript library that provides utility functions for common tasks, such as data manipulation and functional programming. **Special JS Feature or Syntax**: We use two special features in this benchmark: 1. **Set**: This is an ES6 feature (introduced in 2015) that allows you to create a collection of unique values. 2. `Array.from()`: This method converts an iterable object (like a Set or Map) into an array. **Comparison**: The two test cases compare the performance of using a `Set` and Lodash's `uniq` function for removing duplicates from an array. **Results**: The latest benchmark result shows that, on Chrome 81 on Mac OS X 10.14.6, the "Set" approach outperforms the "Array" (Lodash) approach by approximately 4.5x. **Pros and Cons**: * **Set**: + Pros: Fast and efficient for removing duplicates from large arrays. + Cons: Requires modern JavaScript environments that support the Set data structure. * **Array** (Lodash): + Pros: Works in older JavaScript environments, including those without ES6 features. + Cons: Slower than using a Set, especially for large arrays. **Other Alternatives**: If you're not using Lodash or don't want to use a Set, other alternatives exist: * Use a plain old array with manual iteration and equality checks (slowest approach). * Utilize JavaScript's built-in `Map` data structure (similar to Set, but with more flexibility). I hope this explanation helps you understand the test case!
Related benchmarks:
lodash uniq vs native uniq
uniqBy vs stringify performance
Lodash - uniq
Lodash uniqBy vs Javascript uniqBy
lodash uniq vs spread new Set() medium size
Comments
Confirm delete:
Do you really want to delete benchmark?