Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash sortBy vs orderBy 2x
(version: 0)
Lodash sortBy vs orderBy
Comparing performance of:
_.sortBy vs _.orderBy
Created:
4 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):
I'll break down the provided benchmark and explain what's being tested. **Benchmark Overview** The benchmark measures the performance of two functions from the Lodash library: `_.sortBy` and `_.orderBy`. Both functions sort an array of objects based on a specified key ("value" in this case). **Script Preparation Code** The script preparation code generates an array of 100,000 objects with random "value" properties. This creates a large dataset for the sorting algorithms to operate on. **HTML Preparation Code** The HTML preparation code includes a reference to the Lodash library, specifically version 4.17.5, which is used by the benchmark. **Individual Test Cases** There are two test cases: 1. `_.sortBy(arr, "value")`: This tests the sorting function that sorts the array in ascending order based on the "value" key. 2. `_.orderBy(arr, "value")`: This tests the sorting function that sorts the array in descending order based on the "value" key. **Comparison of Options** The two options being compared are: * Ascending sort (`_.sortBy`) * Descending sort (`_.orderBy`) Pros and Cons: * **Ascending Sort (_.sortBy)**: + Pros: Suitable for most use cases, easy to implement. + Cons: May not be as efficient for large datasets or complex sorting requirements. * **Descending Sort (_.orderBy)**: + Pros: Can be faster than ascending sort for large datasets, suitable for specific use cases like top-N ranking. + Cons: May require additional logic to invert the sorted order. **Library and Its Purpose** Lodash is a popular JavaScript utility library that provides a collection of functional programming helpers, including sorting functions. The `_.sortBy` and `_.orderBy` functions are part of this library, offering a convenient way to sort arrays based on specific keys. **Special JS Feature or Syntax** There doesn't seem to be any special JavaScript features or syntax being used in the benchmark. However, it's worth noting that Lodash is often used with ES6+ syntax and modern JavaScript versions. **Other Alternatives** If you're looking for alternatives to Lodash or want to implement your own sorting algorithms, consider the following: * **Native JavaScript Sorting**: You can use built-in JavaScript sorting functions like `Array.prototype.sort()`, which are efficient but may not offer the same level of flexibility as Lodash's sorting functions. * **Other Library Options**: Other popular JavaScript libraries for utility functions include Ramda, Underscore.js, and Moment.js. In summary, the benchmark compares the performance of two sorting functions from Lodash: `_.sortBy` (ascending sort) and `_.orderBy` (descending sort). The test measures which function is faster in a specific use case (sorting an array of objects based on a "value" key).
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?