Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash uniqBy vs Set
(version: 0)
Comparing performance of:
Lodash uniqBy vs Set
Created:
6 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: 40}, () => 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:
10 days ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36 Edg/147.0.0.0
Browser/OS:
Chrome 147 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash uniqBy
1717967.4 Ops/sec
Set
1323414.9 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the benchmark. **Benchmark Overview** The provided JSON represents a JavaScript microbenchmarking test, specifically comparing two approaches for removing duplicates from an array: using Lodash's `uniqBy` function and creating a Set object. **What is being tested?** In this benchmark, we have two main variables: 1. `MyArr`: an array of 40 random numbers generated using `Math.random()` and `Array.from()`. 2. `myCopy`: the resulting array after removing duplicates. The test case consists of two sub-cases: 1. **Lodash uniqBy**: The benchmark uses Lodash's `uniqBy` function to remove duplicates from `MyArr`. The purpose of this approach is to demonstrate how a library like Lodash can simplify the process of finding unique elements in an array. 2. **Set**: This sub-case creates a new Set object from `MyArr`, which automatically removes duplicate values. The purpose of this approach is to show how creating a set from an array can be an efficient way to remove duplicates. **Options compared** The two options being compared are: 1. Using Lodash's `uniqBy` function 2. Creating a Set object from the original array These approaches differ in several ways: * **Library usage**: One approach uses an external library (Lodash), while the other doesn't rely on any additional libraries. * **Implementation details**: `uniqBy` is designed to remove duplicates based on a specific predicate function, whereas creating a Set simply checks for duplicate values. **Pros and Cons** Here's a brief analysis of each approach: 1. **Lodash uniqBy**: * Pros: Simplifies the process of removing duplicates by providing a reusable function. * Cons: Requires an additional library (Lodash), which might introduce overhead or dependencies. 2. **Set**: * Pros: Creates an efficient way to remove duplicates without relying on external libraries. * Cons: Might require more manual setup and handling for edge cases. **Library usage - Lodash** The `uniqBy` function is part of the Lodash library, which provides a set of utility functions for various tasks. In this context, `uniqBy` takes an array and a predicate function as input, returning a new array with unique elements based on the provided criteria. The library's purpose is to simplify common operations like removing duplicates. **Special JS feature or syntax** This benchmark doesn't appear to use any special JavaScript features or syntax that would impact its performance or execution. However, if we were to modify the test case to include such features, it might involve things like: * Using `for...of` loops instead of array methods * Leveraging new array methods (e.g., `map()`, `filter()`) for comparison * Using Web Workers or other parallel processing techniques For this specific benchmark, those approaches would likely have a negligible impact on the results. **Other alternatives** Some alternative approaches to removing duplicates from an array include: 1. **Manual iteration**: Looping through the array and adding elements to a new array while skipping duplicates. 2. **Using `filter()` with a callback function**: Applying a callback function to each element in the array, filtering out those that don't meet certain conditions. 3. **Utilizing `reduce()` or other aggregation functions**: Using accumulator-based functions like `reduce()` or `some()` to find unique elements. These alternatives might not be as efficient as using an external library like Lodash or creating a Set object, but they could provide insight into different implementation strategies for solving the problem.
Related benchmarks:
Lodash uniqBy vs Set 10000
Unique lodash vs vanilla
Lodash uniqBy vs Set vs Set spread
New set vs UniqWith
Comments
Confirm delete:
Do you really want to delete benchmark?