Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash uniqBy vs Map destructuring
(version: 0)
Lodash uniqBy vs [...new Map()]
Comparing performance of:
Lodash uniqBy vs new Map() Destructuring
Created:
4 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: 16000 }, () => ({ someData: 123, value: Math.floor(Math.random() * 1000) })); var myCopy = null;
Tests:
Lodash uniqBy
myCopy = _.uniqBy(myArr, 'value').map(({ value }) => value);
new Map() Destructuring
myCopy = [...new Map(myArr.map((el) => [el.value, el])).values()];
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash uniqBy
new Map() Destructuring
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
3 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36
Browser/OS:
Chrome 145 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash uniqBy
5107.9 Ops/sec
new Map() Destructuring
2210.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested, compared, and their pros and cons. **What's being tested:** Two individual test cases are being compared: 1. Lodash `uniqBy` function 2. The destructuring of a new Map using the spread operator (`[...new Map()]`) The test case uses an array `myArr` with 16,000 elements, each containing two properties: `someData` and `value`. The purpose of this setup is to create a scenario where both functions are called repeatedly, allowing for a fair comparison. **Options compared:** * Lodash `uniqBy` + **Pros:** Well-established and widely-used library, provides a simple way to remove duplicates based on a specific property. + **Cons:** May be slower than native JavaScript solutions due to its overhead. * Destructuring of a new Map using the spread operator (`[...new Map()]`) + **Pros:** Native JavaScript solution that avoids external library dependencies and has low overhead. + **Cons:** Requires manual handling of object keys as map values, which can be error-prone. **Library: Lodash** Lodash is a popular utility library for JavaScript. `uniqBy` is one of its functions, designed to remove duplicate elements from an array based on the value of a specific property. In this benchmark, it's used to compare its performance with the native JavaScript solution using Map destructuring. **Special JS feature or syntax:** There are no special JavaScript features or syntaxes being tested in this benchmark. The focus is solely on comparing the performance of two different approaches. **Benchmark preparation code** The preparation code sets up an array `myArr` and initializes a variable `myCopy` to null, which will be used by both test cases. The HTML preparation code includes the Lodash library from a CDN. **Individual test cases** Each test case defines a specific benchmarking scenario: 1. "Lodash uniqBy": Uses the `uniqBy` function from Lodash to remove duplicates from `myArr` based on the `value` property, and then maps over the resulting array using destructuring. 2. "new Map() Destructuring": Creates a new Map from `myArr`, extracts the values, and then uses the spread operator to convert it into an array. **Latest benchmark result** The provided results show the execution count per second for each test case on a Chrome 111 browser running on a Mac OS X 10.15.7 system. The "Lodash uniqBy" test outperforms the native Map destructuring solution, but with a close margin. **Other alternatives:** Other alternatives to comparing performance in this benchmark could be: * Using other libraries or functions for removing duplicates (e.g., `Set`, `Filter()`) * Comparing with JavaScript's built-in `reduce()` function * Using different data structures or algorithms (e.g., using a heap or priority queue) * Considering factors like memory usage, cache performance, or parallelization
Related benchmarks:
uniqBy vs stringify performance
Lodash uniqBy vs Set with Array of object
lodash vs map 4
Uniq by sorting test 2
Comments
Confirm delete:
Do you really want to delete benchmark?