Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
SortBy vs OrderBy vs MaxBy
(version: 1)
Comparing performance of:
_.sortBy vs _.orderBy vs _.maxBy
Created:
3 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 getRandomInt(max) { return Math.floor(Math.random() * Math.floor(max)); } var arr = []; for(var i = 0; i < 100000; i++){ arr.push({value:getRandomInt(100)}); }
Tests:
_.sortBy
_.sortBy(arr,"value","desc")[0];
_.orderBy
_.orderBy(arr,"value","desc")[0];
_.maxBy
_.maxBy(arr, "value","desc")[0];
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
_.sortBy
_.orderBy
_.maxBy
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the provided JSON data and explain what's being tested, compared, and the pros and cons of each approach. **Benchmark Overview** The benchmark measures the performance of three sorting functions: `_.sortBy`, `_.orderBy`, and `_.maxBy`. These functions are part of the Lodash library. The test generates an array of 100,000 objects with random values between 0 and 100, and then calls each sorting function on this array. **Library: Lodash** Lodash is a popular JavaScript utility library that provides various functions for tasks such as array manipulation, string manipulation, object manipulation, and more. The three sorting functions being tested are part of the Lodash `utility` module. **Sorting Functions** 1. **_.sortBy(arr, "value", "desc")[0]** * This function sorts the array in descending order based on the value property. * Pros: Simple to use, easy to understand. * Cons: May not be optimal for very large datasets due to its simplicity and potential overhead from sorting. 2. **_.orderBy(arr, "value", "desc")[0]** * This function sorts the array in descending order based on the value property, similar to _.sortBy. However, it uses a more complex algorithm that may be optimized for performance. * Pros: May be faster than _.sortBy due to its optimized algorithm. * Cons: Less intuitive and less easy to understand compared to _.sortBy. 3. **_.maxBy(arr, "value", "desc")[0]** * This function returns the object with the maximum value in the array. * Pros: Simple to use, easy to understand. * Cons: May not be optimal for finding the maximum value if the dataset is very large, as it requires scanning the entire array. **Other Considerations** * The test uses a random array generation function (`getRandomInt`) to create a diverse set of data, which helps to reduce the impact of any potential biases. * The benchmark runs on a desktop platform with Chrome 108, which may not be representative of all platforms or browsers. * The `ExecutionsPerSecond` metric provides an estimate of the performance of each function. However, this value can be affected by various factors such as system load, network conditions, and more. **Alternatives** There are alternative sorting algorithms available in JavaScript, including: 1. **Array.prototype.sort()**: This is a built-in method that sorts an array based on the values of its elements. 2. **JavaScript's native sort() method with custom compare function**: This allows for fine-grained control over the sorting process and can be more efficient than using Lodash functions. 3. **Other libraries or frameworks**: Depending on the specific use case, other libraries like Mojs or Paper.js might provide optimized sorting algorithms. In summary, the benchmark provides a useful comparison of three different sorting functions from Lodash, highlighting their strengths and weaknesses. The results can serve as a starting point for further exploration of optimization techniques and alternative sorting algorithms.
Related benchmarks:
Lodash orderBy vs array.prototype.sort
Lodash orderBy() vs array.prototype.sort
Lodash orderBy vs array.prototype.sort fork
Lodash orderBy (fn) vs array.prototype.sort small array
Comments
Confirm delete:
Do you really want to delete benchmark?