Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash vs es6 map
(version: 0)
Comparing performance of:
lodash uniq vs es6 map
Created:
5 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 data = [{a: 1}, {a: 2}, {a: 3}, {a: 4}, {a: 5}, {a: 6}, {a: 7}, {a: 8}, {a: 1}];
Tests:
lodash uniq
_.uniqBy(data, 'a');
es6 map
const uniqBy = (arr, predicate) => { const cb = typeof predicate === 'function' ? predicate : (o) => o[predicate]; return [...arr.reduce((map, item) => { const key = (item === null || item === undefined) ? item : cb(item); map.has(key) || map.set(key, item); return map; }, new Map()).values()]; }; uniqBy(data, 'a')
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash uniq
es6 map
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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser/OS:
Chrome 120 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash uniq
4577526.0 Ops/sec
es6 map
963117.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and its test cases. **Benchmark Definition JSON** The `Script Preparation Code` section defines an array of objects with a single property named `a`. This data structure will be used as input for the benchmarks. The `Html Preparation Code` section includes a reference to the Lodash library, which is a popular utility library for JavaScript. The version specified (4.17.5) is not essential to understanding this benchmark, but it's worth noting that different versions of Lodash might have slightly varying performance characteristics. **Individual Test Cases** There are two test cases: 1. **Lodash `uniqBy` Benchmark** The first test case uses the Lodash `uniqBy` function to remove duplicates from the input data based on the value of property `a`. The function takes an array and a predicate function as arguments, which specifies how to extract the unique identifier for each element. Pros: * The use of Lodash's optimized implementation of the `uniqBy` function means that the code is written in a concise and efficient manner. * Lodash provides a well-tested and widely-used library, which reduces the likelihood of errors or unexpected behavior. Cons: * As with any external library, there might be additional dependencies or overhead associated with using Lodash. 2. **ES6 Map Benchmark** The second test case implements the `uniqBy` functionality from scratch using ES6 Maps. This approach provides a more fundamental understanding of how to achieve similar results without relying on an external library. Pros: * By writing the code manually, you gain insight into the inner workings of the implementation and can potentially optimize it for specific use cases. * This approach is self-contained and does not introduce any additional dependencies or overhead. Cons: * The implementation may be less concise or efficient than the Lodash version, especially considering the added complexity of handling edge cases (e.g., null or undefined values). **Special Considerations** There are no special JavaScript features or syntax used in this benchmark that require a deep understanding of those concepts. **Alternative Approaches** Some possible alternative approaches for implementing the `uniqBy` functionality include: * Using `Array.prototype.reduce()` and `Object.create()` to achieve similar results. * Utilizing a third-party library like `moment.js` for date-based uniqueness (not applicable in this case, as there is no date-related data). * Implementing a custom hash function to create unique identifiers (potentially slower than the approach used in the benchmark). Overall, both test cases provide valuable insights into how different approaches can be taken to achieve similar results. The Lodash implementation demonstrates the benefits of using optimized libraries for repetitive tasks, while the ES6 Map implementation provides a fundamental understanding of how to implement uniqueness logic from scratch.
Related benchmarks:
Array.prototype.map vs Lodash.map
lodash _.map vs native map true version
Ladash map versus ECMA6 map
Array Map Vs Lodash Map (1)
Comments
Confirm delete:
Do you really want to delete benchmark?