Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash "uniqWith" "unionBy" "uniqBy" yummy
(version: 0)
Comparing performance of:
uniqWith vs unionBy vs uniqBy vs uniqBy tradicional
Created:
2 years 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 Preparation code:
var users = [ { 'name': 'barney', 'age': 36 }, { 'name': 'pebbles', 'age': 5 } ]; var newUsers = [ { 'name': 'fred', 'age': 40 }, { 'name': 'barney', 'age': 36 }, { 'name': 'pebbles', 'age': 2 } ]; for(let i = 0; i < 2000; i++) { var newUser = { 'name': 'user_' + i, 'age': Math.floor(Math.random() * i) }; newUsers.push(newUser); }
Tests:
uniqWith
const unionUsers1 = _.uniqWith(newUsers.concat(users), _.isEqual);
unionBy
const unionUsers2 = _.unionBy(newUsers, users, 'name');
uniqBy
const unionUsers1 = _.uniqBy(newUsers.concat(users), element => element.name.toString());
uniqBy tradicional
const unionUsers1 = _.uniqBy(newUsers.concat(users), 'name');
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
uniqWith
unionBy
uniqBy
uniqBy tradicional
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0
Browser/OS:
Chrome 123 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
uniqWith
1.9 Ops/sec
unionBy
9698.9 Ops/sec
uniqBy
9293.5 Ops/sec
uniqBy tradicional
9785.4 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Measuring the performance of JavaScript functions can be a complex task, as it involves understanding various aspects of the language and its ecosystem. The provided JSON benchmark definition represents a test case for comparing three different approaches to merge two arrays: `uniqWith`, `unionBy`, and `uniqBy` with a custom comparison function. The test case uses Lodash, a popular JavaScript utility library. Let's break down each approach: **1. `uniqWith`** This method takes two functions as arguments. The first function is used to merge the arrays, while the second function is used to check for duplicates. In this test case, it calls `_.isEqual` to compare elements, which checks for strict equality. Pros: Simple and efficient way to perform array merging. Cons: May not be suitable for complex data structures or when dealing with objects that have multiple properties. **2. `unionBy`** This method takes three arguments: the two arrays to merge, a key function that specifies how to extract unique values from each element, and an optional value function to provide a default value if the array is empty. Pros: Flexible way to perform array merging based on specific keys or properties. Cons: May be slower than `uniqWith` for large datasets, as it requires additional function calls to extract key values. **3. `uniqBy`** This method takes two arguments: the array to merge and a comparison function that extracts unique values from each element. Pros: Similar to `uniqWith`, but with more control over the comparison logic. Cons: May require more manual effort to implement, especially when dealing with complex data structures or custom keys. Now, let's analyze the provided benchmark results: * `uniqBy tradicional` (traditional approach) is the fastest, with an average execution speed of around 9785 executions per second. * `unionBy` is slightly slower than `uniqBy`, with an average execution speed of around 9698 executions per second. * `uniqWith` is the slowest, with an average execution speed of around 9293 executions per second. The results suggest that using a custom comparison function (as in `uniqBy`) or leveraging Lodash's built-in equality checks (`_.isEqual`) can lead to better performance compared to the traditional approach (`unionBy`). However, this may come at the cost of additional complexity and manual effort.
Related benchmarks:
Lodash "unionWith" "unionBy" "uniqWith" 5
Lodash "unionWith" "unionBy" "uniqBy" 5
Lodash "uniqWith" "unionBy" "uniqBy" 6
Lodash "uniqWith" "unionBy" "uniqBy" 27062023
Lodash "uniqWith" "unionBy" "uniqBy" 8
Comments
Confirm delete:
Do you really want to delete benchmark?