Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash vs map 5
(version: 0)
Comparing performance of:
Lodash uniqBy path vs Map
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 myArr = Array.from({ length: 16000 }, () => ({ value: Math.floor(Math.random() * 1000), val: Math.floor(Math.random() * 1000) })); var myCopy = null;
Tests:
Lodash uniqBy path
myCopy = _.uniqBy(myArr, val => val.toString());
Map
myCopy = [...new Map(myArr.map((obj) => [obj.toString(), obj])).values()];
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash uniqBy path
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/131.0.0.0 Safari/537.36 Edg/131.0.0.0
Browser/OS:
Chrome 131 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash uniqBy path
2388.0 Ops/sec
Map
1905.4 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks! **What is being tested?** MeasureThat.net provides a benchmarking platform for comparing the performance of different approaches to accomplish a specific task in JavaScript. In this case, we have two individual test cases: `Lodash uniqBy path` and `Map`. The goal is to measure which approach is faster: using Lodash's `uniqBy` method with a custom comparison function or using the `Map` API with a similar implementation. **Options being compared:** There are two options being compared: 1. **Lodash's `uniqBy` method**: This is a utility function from the popular JavaScript library Lodash. It takes an array and a comparison function as arguments, returning a new array with duplicate elements removed based on the comparison function. 2. **Map API with custom implementation**: In this approach, we create a Map object from the original array, where each key-value pair is created using the `map` method and the `toString()` method to compare values. **Pros and cons of each approach:** 1. **Lodash's `uniqBy` method**: * Pros: + Efficient implementation with good performance. + Easy to use and understand, as it provides a simple and intuitive API. + Well-maintained and widely adopted library. * Cons: + Adds an external dependency (Lodash) to the test case. + May not be optimized for all specific use cases or edge cases. 2. **Map API with custom implementation**: * Pros: + No external dependencies, as it only uses built-in JavaScript methods. + More control over the implementation and optimization of the code. * Cons: + Requires more manual effort to implement and maintain, especially for complex use cases. + May be slower than Lodash's `uniqBy` method due to additional overhead. **Library:** In this benchmark, Lodash is used as a library. It provides a collection of reusable functions that make it easy to perform common tasks in JavaScript. In this specific case, the `uniqBy` function is used to remove duplicate elements from an array based on a custom comparison function. **Special JS feature or syntax:** There is no special JavaScript feature or syntax being tested or utilized in this benchmark. The code only uses built-in JavaScript methods and libraries like Lodash. **Benchmark preparation code:** The benchmark preparation code creates two arrays, `myArr` and `myCopy`, where `myCopy` is a copy of `myArr`. This setup ensures that the test cases are comparing equal-sized inputs with similar data distributions. **Other alternatives:** If you want to compare other approaches or libraries for removing duplicate elements from an array, some alternative options could be: * Using the `Set` API instead of Lodash's `uniqBy` * Implementing a custom sorting function using the `Array.prototype.sort()` method * Using a library like `ramda` or `underscore.js` that provides similar functionality to Lodash Keep in mind that each alternative may have its own trade-offs, pros, and cons, and may not be as efficient or easy to use as Lodash's `uniqBy` method.
Related benchmarks:
Array.prototype.map vs Lodash.map on large data
Lodash uniqBy vs Map destructuring
lodash vs map 4
native map vs lodash map on large array
Comments
Confirm delete:
Do you really want to delete benchmark?