Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash uniqBy vs Javascript uniqBy with key
(version: 0)
Comparing performance of:
Native uniqueBy vs Lodash uniqBy
Created:
2 years ago
by:
Registered User
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 users = [ { 'user': 'joey', 'age': 29 }, { 'user': 'joey', 'age': 32 }, { 'user': 'ross', 'age': 41 }, { 'user': 'ross', 'age': 25 }, { 'user': 'ross', 'age': 48 }, { 'user': 'chandler', 'age': 39 }, { 'user': 'chandler', 'age': 12 }, { 'user': 'chandler', 'age': 41 } ]
Tests:
Native uniqueBy
const uniqueBy = (array, key) => array.filter((value, index, self) => self.findIndex((item) => item[key] === value[key]) === index); let uniqued = uniqueBy(users, 'user');
Lodash uniqBy
let uniqued = _.uniqBy(users, ['user']);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Native uniqueBy
Lodash uniqBy
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Explanation** The provided JSON represents two microbenchmarks, both testing the uniqueness filtering functionality of arrays. The benchmarks are: 1. `Native uniqueBy`: This test compares the performance of the native JavaScript method `Array.prototype.filter()` used in conjunction with the `findIndex()` and comparison operator (`===`) to find unique elements. 2. `Lodash uniqBy`: This test compares the performance of the popular JavaScript library Lodash's `uniqBy` function, which is designed specifically for uniqueness filtering. **Comparison Options** The two tests compare different approaches to achieving uniqueness filtering: 1. **Native `Array.prototype.filter()`**: This approach uses the native JavaScript method to filter the array and find unique elements. It relies on the `findIndex()` method to identify unique values and then filters out duplicates. 2. **Lodash's `uniqBy` function**: This approach uses Lodash's dedicated function for uniqueness filtering, which is optimized for performance. **Pros and Cons** Here are some pros and cons of each approach: 1. **Native `Array.prototype.filter()`**: * Pros: Native implementation, potentially faster since it avoids a library overhead. * Cons: Requires manual implementation of the filtering logic, might not be as efficient for large datasets due to its iterative nature. 2. **Lodash's `uniqBy` function**: * Pros: Optimized and tested for performance, provides a simple and concise API. * Cons: Introduces an external library dependency, which may impact performance or lead to additional overhead. **Library Description** In this benchmark, Lodash is used as the utility library for the `uniqBy` function. Lodash is a popular JavaScript library that provides a collection of reusable functions for various tasks, including array manipulation and filtering. **Special JS Features/Syntax** There are no specific JavaScript features or syntaxes being tested in this benchmark beyond the standard `Array.prototype.filter()` method and Lodash's `uniqBy` function. **Other Alternatives** If you were to implement a custom uniqueness filtering solution without relying on Lodash, you might consider using: 1. **`Set` data structure**: Using a `Set` to store unique values could provide an efficient way to filter out duplicates. 2. **`Map` data structure**: Similar to `Set`, a `Map` could be used to keep track of unique values and filter out duplicates. Keep in mind that these alternatives might not be as optimized or concise as Lodash's `uniqBy` function, but they can provide an interesting alternative implementation perspective.
Related benchmarks:
Lodash "uniqWith" "unionBy" "uniqBy" 6
Lodash "uniqWith" "unionBy" "uniqBy" 27062023
Native uniqueBy vs Lodash _.uniqBy
Lodash "uniqWith" "unionBy" "uniqBy" 8
Comments
Confirm delete:
Do you really want to delete benchmark?