Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Uniq by sorting test
(version: 0)
Comparing performance of:
Lodash uniqBy vs Custom uniq array
Created:
one year ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js'></script>
Script Preparation code:
var myArr = Array.from({ length: 16000 }, () => ({ value: Math.floor(Math.random() * 1000) })); var myCopy = null;
Tests:
Lodash uniqBy
myCopy = _.uniqBy(myArr, 'value');
Custom uniq array
const itemIdSet = new Set(myArr.map(item => item.value)); const uniqueItems = []; itemIdSet.forEach(value => { const uniqueItem = myArr.find(item => item.value === value); if (uniqueItem) uniqueItems.push(uniqueItem); }); myCopy = uniqueItems;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash uniqBy
Custom uniq array
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/126.0.0.0 Safari/537.36 Edg/126.0.0.0
Browser/OS:
Chrome 126 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash uniqBy
3437.6 Ops/sec
Custom uniq array
823.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the provided benchmark definitions and explain what's being tested, compared options, pros and cons, and other considerations. **Benchmark Definition** The provided benchmark definition is a JSON object that contains the following information: * `Name`: A unique name for the benchmark. * `Description`: An optional description of the benchmark (not used in this case). * `Script Preparation Code`: A JavaScript code snippet that prepares the data for the benchmark. In this case, it creates an array of 16,000 objects with a random value between 0 and 999. * `Html Preparation Code`: A script tag that includes the Lodash library version 4.17.21. **Individual Test Cases** There are two test cases: 1. **Lodash uniqBy** * `Benchmark Definition`: The code snippet `myCopy = _.uniqBy(myArr, 'value');` uses the Lodash library to create a new array with unique elements based on the value property. 2. **Custom uniq array** * `Benchmark Definition`: The code snippet creates two arrays: `itemIdSet` and `uniqueItems`. It then iterates over `itemIdSet`, finds the corresponding element in `myArr` using `find()`, and pushes it to `uniqueItems` if found. **What's being tested?** Both test cases are measuring the performance of unique array creation. The first test case uses a well-known library (Lodash), while the second test case implements a custom solution. **Options compared** The two options being compared are: 1. **Lodash uniqBy**: Uses the `uniqBy` function from Lodash to create a new array with unique elements. 2. **Custom uniq array**: Manually creates an array of unique elements using a loop and the `find()` method. **Pros and Cons** * **Lodash uniqBy** + Pros: - Well-established library with optimized performance. - Easy to use and understand. + Cons: - Requires an additional library dependency (Lodash). - May have a higher overhead due to the library's complexity. * **Custom uniq array** + Pros: - No external dependencies required. - Can be optimized for specific use cases or performance requirements. + Cons: - More complex and harder to understand, especially for those without experience with manual iteration and array manipulation. - May not be as efficient as the optimized Lodash implementation. **Other Considerations** * **Performance**: Both tests create a large array of unique elements, so the results are sensitive to the performance characteristics of each approach. The test case that uses `uniqBy` is likely to have better performance due to Lodash's optimization and caching. * **Code readability and maintainability**: The custom implementation may be harder to understand and maintain, especially for developers without experience with manual array manipulation. **Browser-specific considerations** The benchmark results are for a specific browser (Chrome 126) and device platform (Desktop). This means that the performance differences between Lodash `uniqBy` and the custom implementation might not be apparent in other browsers or devices.
Related benchmarks:
Unique lodash vs vanilla
Lodash uniqBy vs Map destructuring
lodash uniqBy vs custom uniqBy
Uniq by sorting test 2
Comments
Confirm delete:
Do you really want to delete benchmark?