Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash uniqBy vs Set 10000
(version: 0)
Comparing performance of:
Lodash uniqBy vs Set
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:
var MyArr = Array.from({length: 10000}, () => Math.floor(Math.random() * 40)); var myCopy = null;
Tests:
Lodash uniqBy
myCopy = _.uniqBy(MyArr);
Set
myCopy = [...new Set(MyArr)]
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash uniqBy
Set
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36
Browser/OS:
Chrome 129 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash uniqBy
12496.2 Ops/sec
Set
5941.9 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks and explore what's being tested in this specific benchmark. **Benchmark Overview** The benchmark compares the performance of two approaches to remove duplicate elements from an array: 1. Lodash's `uniqBy` function 2. The `Set` object (a built-in JavaScript data structure) **Lodash uniqBy** Lodash is a popular JavaScript utility library that provides a wide range of functional programming helpers. In this case, `uniqBy` is used to remove duplicate elements from an array based on a specified key. When the benchmark runs, Lodash's `uniqBy` function is executed with the `MyArr` array as input. The resulting unique array is stored in the `myCopy` variable. **Set** The `Set` object is a built-in JavaScript data structure that stores unique values. In this benchmark, it's used to create a set from the `MyArr` array and then convert it back to an array using the spread operator (`[...]`). **Options Comparison** There are two main options being compared: 1. **Lodash uniqBy**: This approach uses Lodash's `uniqBy` function to remove duplicates based on the specified key. 2. **Set**: This approach uses a built-in JavaScript data structure (`Set`) to store unique values. **Pros and Cons of Each Approach** Here are some pros and cons of each approach: * **Lodash uniqBy**: + Pros: Lodash provides a convenient and efficient way to remove duplicates, and it's well-tested and widely used. + Cons: It requires an additional library (Lodash) and may introduce additional overhead due to its complexity. * **Set**: + Pros: It's a built-in JavaScript data structure, so no additional libraries are required. It's also relatively lightweight and efficient. + Cons: It may not be as convenient or expressive as Lodash's `uniqBy` function. **Library and Purpose** In this benchmark, the library being used is Lodash (version 4.17.5). The purpose of Lodash is to provide a set of utility functions that make it easier to write JavaScript code, particularly functional programming code. **Special JS Feature or Syntax** There doesn't appear to be any special JavaScript features or syntax being tested in this benchmark. Both `uniqBy` and the `Set` approach rely on standard JavaScript language features. **Other Alternatives** If you're looking for alternative approaches to remove duplicates from an array, here are a few options: * **Using `reduce()`**: You can use the `reduce()` method to create a new array with unique elements. * **Using `filter()` and `includes()`**: You can use `filter()` to create a new array with unique elements and then check for existence using `includes()`. * **Using `Array.from()` and `Set`**: As shown in this benchmark, you can use `Array.from()` to convert an iterable to an array and then pass it to a `Set`, which will automatically remove duplicates. I hope this explanation helps! Let me know if you have any further questions.
Related benchmarks:
Lodash uniqBy vs Set
Lodash uniqBy vs Set with Array of object
Unique lodash vs vanilla
Lodash uniqBy vs Set vs Set spread
Comments
Confirm delete:
Do you really want to delete benchmark?