Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash sortBy vs orderBy corrected
(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):
Let's break down the provided JSON and explain what is being tested, compared, and their pros and cons. **Benchmark Definition** The benchmark defines two test cases: 1. `_.sortBy(arr,"value")` 2. `_.orderBy(arr,"value")` These two functions are part of the Lodash library, which provides a set of functional programming helpers in JavaScript. **Lodash Library** Lodash is a popular JavaScript utility library that offers various functions for tasks such as array manipulation, object transformation, and more. The `sortBy` and `orderBy` functions are specifically designed to sort arrays based on a given property. **Script Preparation Code** The script preparation code generates an array of 100,000 objects with a random "value" property between 0 and 100. This creates a large dataset for the benchmark. **Html Preparation Code** The HTML preparation code includes a reference to Lodash version 4.17.5, which is used in the benchmark. **Options Compared** In this benchmark, two options are compared: 1. `_.sortBy(arr,"value")` 2. `_.orderBy(arr,"value")` Both functions sort the array in ascending order based on the "value" property. However, they use different algorithms to achieve this: * `_.sortBy` uses a stable sorting algorithm that ensures the original order of equal elements is preserved. * `_.orderBy` also uses a stable sorting algorithm, but it's not explicitly stated which one. **Pros and Cons** Here are some pros and cons of each approach: * `_.sortBy`: + Pros: - Preserves the original order of equal elements. - May be faster for small datasets due to its simplicity. + Cons: - May not be as efficient for large datasets due to its stability requirements. * `_.orderBy`: + Pros: - Is designed specifically for sorting and may be more optimized for performance. + Cons: - Does not preserve the original order of equal elements, which might be a drawback in certain scenarios. **Special JS Feature or Syntax** There is no special JavaScript feature or syntax being tested in this benchmark. However, it's worth noting that the use of Lodash functions like `sortBy` and `orderBy` relies on the fact that these functions are implemented in terms of more fundamental operations, such as comparing elements using the `<`, `>`, etc. operators. **Alternatives** Other alternatives for sorting arrays include: * Built-in JavaScript methods: `Array.prototype.sort()` * Other third-party libraries or implementations: e.g., [ramda](https://ramdajs.com/), [underscore.js](https://github.com/jashkenaz/underscore) In general, the choice of sorting algorithm and library depends on the specific requirements of your application, such as performance, stability, and ease of use.
Related benchmarks:
Lodash orderBy() vs array.prototype.sort
lodash sortBy vs native sortBy 4.17.21
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?