Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Set of array
(version: 0)
Comparing performance of:
Lodash uniqe vs Set
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:
Lodash uniqe
var l = [1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7]; return _.uniq(l);
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;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash uniqe
Set
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):
I'll explain what's being tested in the provided JSON, compare the different approaches, and discuss their pros and cons. **What's being tested?** The benchmark is testing two approaches to remove duplicates from an array: 1. **Lodash `uniq` function**: This function takes an array as input and returns a new array with duplicate elements removed. 2. **Array.from(new Set())**: This approach uses the `Set` object to remove duplicates from the array. When you create a set, all elements are unique by definition. Then, we use `Array.from()` to convert the set back into an array. **Options being compared** The two options being compared are: * **Lodash `uniq` function**: This is a third-party library function that provides a concise way to remove duplicates from an array. * **Array.from(new Set())**: This is a built-in JavaScript approach that uses the `Set` object to remove duplicates. **Pros and Cons of each approach** **Lodash `uniq` function** Pros: * Concise and readable code * Easy to use and understand * Well-maintained and widely used library Cons: * Adds additional overhead due to the use of a third-party library * May not be as fast as a built-in implementation (although this may depend on the specific version of Lodash) **Array.from(new Set())** Pros: * Built-in implementation, so no additional overhead * Can be faster than using a third-party library (since it doesn't involve a function call) * Uses a simple and efficient data structure (sets) Cons: * May require more code to achieve the same result as Lodash `uniq` * Less readable code for someone unfamiliar with sets **Library: Lodash** Lodash is a popular JavaScript utility library that provides many useful functions for tasks like array manipulation, object transformation, and functional programming. In this case, the `uniq` function is used to remove duplicates from an array. **Special JS feature/syntax: None mentioned in this benchmark** Since there are no special JavaScript features or syntaxes being used in this benchmark, I won't mention anything about them. **Other alternatives** If you're looking for alternative approaches to remove duplicates from an array, here are a few options: * Using `filter()` and checking for equality with the first element: `arr.filter((x, i) => x !== arr[i])` * Using `reduce()` to create a new array with unique elements: `arr.reduce((acc, x) => acc.includes(x) ? acc : [x], [])` * Using `Array.prototype.every()` and checking if all elements are unique: `arr.every((x, i) => !arr.slice(i).includes(x))` These alternatives may have different performance characteristics or readability profiles compared to the Lodash `uniq` function and the `Array.from(new Set())` approach.
Related benchmarks:
CircleSmallTest
Lodash compact
lodash slice
isEmpty vs. vanilla
_.compact vs array.filter
Comments
Confirm delete:
Do you really want to delete benchmark?