Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Native uniqueBy vs Lodash _.uniqBy
(version: 0)
Comparing performance of:
Native uniqueBy vs Lodash uniqBy
Created:
2 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 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) => [...new Map(array.map(item => [item[key], item])).values()]; 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:
Run details:
(Test run date:
11 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Browser/OS:
Chrome 137 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Native uniqueBy
7020707.5 Ops/sec
Lodash uniqBy
7897381.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Overview** MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks. In this case, we have two benchmark test cases: `Native uniqueBy` and `Lodash uniqBy`. These tests compare the performance of two approaches to remove duplicates from an array based on a specific key. **Benchmark Definitions** The benchmark definitions are provided in JSON format. Here's a breakdown of each definition: 1. **Name**: The name of the benchmark, which is "Native uniqueBy vs Lodash _.uniqBy". 2. **Description**: An empty string indicating that there is no description for this benchmark. 3. **Script Preparation Code**: A JavaScript code snippet that creates an array of objects with a common key ('user') and some duplicate values. The script preparation code defines the input data `users` which has duplicates based on the 'user' key. This data will be used to test the uniqueness removal function. 4. **Html Preparation Code**: A line of HTML code that includes a reference to the Lodash library (version 4.17.5) from a CDN. This indicates that the `Lodash uniqBy` test case uses the Lodash library for its functionality. **Test Cases** There are two individual test cases: 1. **Native uniqueBy**: This test case defines a native JavaScript function called `uniqueBy` that takes an array and a key as arguments, and returns an array of unique values based on that key. 2. **Lodash uniqBy**: This test case defines another function call using the Lodash library's `_uniqBy` function, which is similar to the native implementation but uses the Lodash library for its functionality. **Options Compared** The two test cases compare the performance of: * A native JavaScript implementation (`uniqueBy`) * The `uniqBy` function from the Lodash library **Pros and Cons** Here are some pros and cons for each approach: 1. **Native uniqueBy** * Pros: + Native code, which can be optimized by the browser's Just-In-Time (JIT) compiler. + No dependencies on external libraries. * Cons: + May not have the same level of precision or quality control as a library implementation. 2. **Lodash uniqBy** * Pros: + Well-tested and maintained by the Lodash community. + Often provides additional features and options (e.g., sorting, stability). * Cons: + Requires loading an external library, which can impact performance. + May have a smaller codebase or more dependencies compared to native implementations. **Library: Lodash** Lodash is a popular JavaScript utility library that provides various functions for tasks like array manipulation, object processing, and string manipulation. The `uniqBy` function in particular helps remove duplicates from an array based on a specified key. **Special JS Feature or Syntax** Neither of the test cases uses any special JavaScript features or syntax beyond standard JavaScript language constructs.
Related benchmarks:
Lodash "uniqWith" "unionBy" "uniqBy" 6 Custom
Lodash "uniqWith" "unionBy" "uniqBy" 27062023
Lodash uniqBy vs Javascript uniqBy with key
Lodash "uniqWith" "unionBy" "uniqBy" 8
Comments
Confirm delete:
Do you really want to delete benchmark?