Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash Uniq vs Lodash UniqBy vs Javascript Set
(version: 0)
Comparing performance of:
Lodash UniqBy vs Javascript Set vs Lodash Uniq
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.5/lodash.min.js"></script>
Script Preparation code:
var firstEqual = []; var secondEqual = []; for (var i=0; i<1000; i++) { firstEqual.push({a: {b: {c: i}}}); secondEqual.push({a: {b: {c: i}}}); } var arr = [...firstEqual, ...secondEqual];
Tests:
Lodash UniqBy
_.uniqBy(arr, 'a.b.c').map(el =>el.a.b.c)
Javascript Set
[...new Set(arr.map(el => el.a.b.c))]
Lodash Uniq
_.uniq(arr.map(el => el.a.b.c))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Lodash UniqBy
Javascript Set
Lodash Uniq
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
3 months ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36
Browser/OS:
Chrome 144 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash UniqBy
4320.0 Ops/sec
Javascript Set
35999.8 Ops/sec
Lodash Uniq
29860.1 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and its options. **Benchmark Overview** The benchmark compares the performance of three approaches to remove duplicates from an array: 1. **Lodash Uniq**: uses the `uniq` function from Lodash library 2. **Lodash UniqBy**: uses the `uniqBy` function from Lodash library, which removes duplicates based on a specific property (in this case, `'a.b.c'`) 3. **Javascript Set**: uses a native JavaScript `Set` data structure to remove duplicates **Options Compared** The three options are compared in terms of their execution speed, measured by the number of executions per second. **Pros and Cons of Each Approach** 1. **Lodash Uniq** * Pros: concise and easy to read code, leverages a well-maintained and widely-used library * Cons: depends on Lodash library, which may not be included in all environments (e.g., older browsers) 2. **Lodash UniqBy** * Pros: similar to `uniq` but provides an additional layer of control over duplicate removal * Cons: adds complexity due to the use of a specific property for duplicate removal, and requires Lodash library 3. **Javascript Set** * Pros: native JavaScript implementation, no external dependencies required, efficient and lightweight * Cons: may require manual handling of edge cases (e.g., null or undefined values), can be less readable due to its functional programming nature **Library and Syntax** The benchmark uses the Lodash library, which is a popular utility library for JavaScript that provides various functions for tasks like string manipulation, array manipulation, and more. The `uniq` and `uniqBy` functions are part of this library. There are no special JavaScript features or syntax used in this benchmark, apart from the use of arrow functions (`=>`) in some cases. **Alternatives** Other alternatives for removing duplicates from an array include: * Using a simple loop to iterate over the array and check for duplicates * Using a combination of `filter()` and `reduce()` functions to remove duplicates * Using a library like Moment.js or Underscore.js, which provide similar functionality to Lodash However, these alternatives may not be as efficient or concise as using a native JavaScript `Set` data structure or the Lodash library. The benchmark's focus on exploring different approaches for removing duplicates from an array makes it a useful resource for developers looking to optimize their code and understand the trade-offs of different methods.
Related benchmarks:
lodash uniq vs native uniq
lodash uniqBy vs custom uniqBy
uniqBy performance lodash vs native
lodash uniq vs spread new Set() medium size
Comments
Confirm delete:
Do you really want to delete benchmark?