Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Comparing performance of: _.uniqWith vs native impl
(version: 4)
Comparing performance of:
imp vs lodash
Created:
7 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:
function _uniqTxes(newSelectedModelList) { return newSelectedModelList.filter(function({ txid }, key) { return !this.has((key = txid)) && this.add(key); }, new Set()); } // Build random data set with duplicates function randomChar() { return 'abcdefghijklmnopqrstuvwxyz'.charAt(Math.floor(Math.random() * 26)); } var data = []; for (var i = 0; i < 50000; i++) { data.push ({ txid: randomChar() + randomChar() +randomChar() }); }
Tests:
imp
_uniqTxes(data)
lodash
_.uniqWith(data, (a, b) => a.txid === b.txid);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
imp
lodash
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:136.0) Gecko/20100101 Firefox/136.0
Browser/OS:
Firefox 136 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
imp
540.1 Ops/sec
lodash
0.5 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 some pros/cons of each approach. **Benchmark Definition** The benchmark is comparing the performance of two approaches to remove duplicates from an array: 1. **Native Implementation**: `_uniqTxes` function (test case "imp") 2. **Lodash Implementation**: Using the `_.uniqWith` function with a custom comparison function (test case "lodash") **What's being tested?** The benchmark is testing how fast each implementation can filter out duplicates from the array. The array contains 50,000 objects with randomly generated IDs (txids). **Options Compared** The two options are compared: 1. **Native Implementation**: `_uniqTxes` function, which uses a combination of `filter` and `has`, `add`, and `Set` methods to remove duplicates. 2. **Lodash Implementation**: Using the `_.uniqWith` function with a custom comparison function `(a, b) => a.txid === b.txid`. This function is part of the Lodash library. **Pros/Cons of each approach** 1. **Native Implementation** ( `_uniqTxes` function ): * Pros: + No external dependencies required. + Can be optimized for performance using techniques like caching and memoization. * Cons: + More verbose code compared to Lodash implementation. + Requires manual management of the `Set` data structure. 2. **Lodash Implementation** (using `_.uniqWith`): * Pros: + Concise and readable code. + Built-in support for various comparison functions, reducing boilerplate code. * Cons: + External dependency on Lodash library. + May have slower performance due to the overhead of calling a function. **Library Used** In this benchmark, the `lodash` library is used. Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks like string manipulation, array processing, and more. The `_.uniqWith` function is part of Lodash's `MoreUtils` module, which provides additional functional programming helpers. **Special JS Feature/Syntax** There isn't any special JavaScript feature or syntax used in this benchmark that requires explanation beyond the basic usage of arrays, objects, and functions.
Related benchmarks:
Create an array with unique values - Javascript Array.reduce/Array.indexOf vs Lodash Uniq vs custom fn
Create an array with unique values - Javascript Array.reduce/Array.indexOf vs Lodash Uniq vs custom fn vs custom2
lodash uniq vs Array.from(new Set()) vs spread new Set() vs for vs for memory optimized 4
JS fastest unique array Set vs uniq vs filter
lodash@4.17.21 uniq vs set vs custom unique
Comments
Confirm delete:
Do you really want to delete benchmark?