Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash uniqBy vs loop+Map
(version: 0)
Comparing performance of:
_.unqiBy vs Loop
Created:
one year 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> <script> const arr = (new Array(10000)).fill().map((e, i) => ({ key: i%2 === 1 ? i : i -1, val1: 'abcdf', val: 'abcdf' })); </script>
Tests:
_.unqiBy
const res = _.uniqBy(arr, 'key')
Loop
const result = new Map(); for (const item of arr) { const key = item['key']; result.set(key, item); } const res = result.values();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
_.unqiBy
Loop
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:133.0) Gecko/20100101 Firefox/133.0
Browser/OS:
Firefox 133 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
_.unqiBy
881.5 Ops/sec
Loop
2226.7 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. **Benchmark Overview** The benchmark compares two approaches to removing duplicates from an array of objects: using Lodash's `uniqBy` function and implementing a custom loop with a `Map` data structure. **Test Cases** There are two test cases: 1. **_.unqiBy**: This test case uses Lodash's `uniqBy` function to remove duplicates from the `arr` array, which contains objects with a `key` property. 2. **Loop**: This test case implements a custom loop using a `Map` data structure to remove duplicates from the `arr` array. **Options Compared** The two approaches being compared are: * Lodash's `uniqBy` function * A custom loop with a `Map` data structure **Pros and Cons of Each Approach** **Lodash's `uniqBy` function:** Pros: * Simple to use and understand, as it relies on the Lodash library. * Optimized for performance by using a efficient algorithm. Cons: * Requires an additional library (Lodash) to be included in the benchmark. * May not perform well if the input data is large or complex. **Custom Loop with `Map`:** Pros: * Does not require any external libraries, making it more lightweight. * Can be optimized for performance by using a custom implementation. Cons: * Requires more code and may be less straightforward to understand. * May not be as efficient as Lodash's `uniqBy` function if implemented poorly. **Library Used:** In this benchmark, the `Map` data structure is used to remove duplicates from the array. A `Map` is a data structure that stores key-value pairs, where each key is unique and maps to a specific value. **Special JS Feature/Syntax:** None of the test cases use any special JavaScript features or syntax. They are written in vanilla JavaScript. **Other Alternatives:** If you need to remove duplicates from an array of objects without using Lodash's `uniqBy` function, other alternatives could be: * Using a `Set` data structure and converting the array to a set before iterating over it. * Using a custom implementation with a sorted array or a tree-based data structure. * Using a library like Moment.js or jQuery that provides similar functionality. In summary, this benchmark compares two approaches to removing duplicates from an array of objects: using Lodash's `uniqBy` function and implementing a custom loop with a `Map` data structure. The choice of approach depends on the specific requirements and constraints of the project.
Related benchmarks:
uniqBy performance
uniqBy vs stringify performance
uniqBy performance ttt
uniqBy performance lodash vs native
uniqBy performance and map
Comments
Confirm delete:
Do you really want to delete benchmark?