Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash sortBy vs orderBy 2
(version: 0)
Lodash sortBy vs orderBy
Comparing performance of:
_.sortBy vs _.orderBy
Created:
6 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:
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");
_.orderBy
_.orderBy(arr,"value");
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
_.sortBy
_.orderBy
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):
**Benchmark Overview** The provided benchmark is designed to compare the performance of two Lodash functions: `sortBy` and `orderBy`. These functions are used to sort an array of objects based on a specific property. **Script Preparation Code** The script preparation code generates an array of 100,000 objects with random `value` properties. This array will be used as input for both the `sortBy` and `orderBy` functions. **Html Preparation Code** The HTML preparation code includes a reference to the Lodash library (version 4.17.5) via a CDN, which allows users to include this library in their own benchmark scripts. **Test Cases** There are two test cases: 1. **_.sortBy(arr, "value")**: This function sorts the `arr` array in ascending order based on the `value` property of each object. 2. **_.orderBy(arr, "value")**: This function also sorts the `arr` array in ascending order based on the `value` property of each object, but it is noted that the performance may vary depending on the device and browser used. **Options Compared** The two functions are compared with different execution frequencies: * **_sortBy**: 21.126760482788086 executions per second * **_orderBy**: 20.71162986755371 executions per second **Pros and Cons of Different Approaches** Both functions have similar performance characteristics, but there might be some differences depending on the specific use case. * **_.sortBy**: This function is generally faster when used with a stable sort order (i.e., always in ascending or descending order). However, its performance may degrade if the input array is not sorted. * **_orderBy**: This function is designed to work with an unstable sort order. If the input array is already sorted, it can be significantly faster than _sortBy. However, its performance may degrade if the input array is not sorted. **Lodash Library** The Lodash library provides a range of useful functions for manipulating arrays and objects. In this benchmark, `sortBy` and `orderBy` are two of these functions that allow users to sort arrays in different ways. **Special JS Feature/Syntax** Neither of these test cases utilizes any special JavaScript features or syntax that would impact the performance difference between _sortBy and _orderBy. **Alternatives** If you want to compare the performance of other sorting algorithms, such as quicksort or mergesort, you can use alternative libraries like [fast-sort](https://www.npmjs.com/package/fast-sort) or [merge-sort](https://github.com/mholt/merge-sort). Alternatively, if you want to explore different sorting strategies that are not part of the Lodash library, you can implement your own sorting algorithms using JavaScript.
Related benchmarks:
Lodash orderBy vs array.prototype.sort
Lodash orderBy() vs array.prototype.sort
Lodash sortBy vs orderBy performance
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?