Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
[FIXED] Lodash sortBy vs orderBy
(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 what's being tested in this JavaScript microbenchmark. **Benchmark Definition** The benchmark is comparing two functions from the Lodash library: `_.sortBy` and `_.orderBy`. These functions are used to sort arrays of objects based on a specified key. **What options are compared?** The options being compared are: 1. `_.sortBy` 2. `_.orderBy` Both functions take an array of objects as input, specify the key to sort by, and return the sorted array. The main difference between them is how they handle duplicate values. * `_.sortBy` uses a stable sorting algorithm that preserves the original order of equal elements. * `_.orderBy` uses an unstable sorting algorithm that may change the order of equal elements. **Pros and Cons** Here's a brief summary: * **_.sortBy** + Pros: - Preserves the original order of equal elements, which can be important in certain applications. - May perform better for large datasets with many duplicate values. + Cons: - Can be slower due to the stable sorting algorithm used. * `_.orderBy` + Pros: - Faster execution times due to the unstable sorting algorithm used. - Suitable for cases where the order of equal elements doesn't matter. + Cons: - May change the order of equal elements, which can be problematic in certain applications. **Library** The Lodash library is a popular utility library for JavaScript that provides a wide range of functions for tasks such as array manipulation, string manipulation, and more. In this benchmark, `_.sortBy` and `_.orderBy` are two specific functions within the library. **Special JS feature/syntax** There is no special JavaScript feature or syntax being tested in this benchmark. The code simply demonstrates how to use Lodash functions to sort arrays of objects. **Other alternatives** If you need to implement sorting functionality manually, you could consider using the `Array.prototype.sort()` method in combination with a callback function that specifies the key to sort by and handles duplicate values. However, this approach would not be suitable for large datasets or performance-critical applications. In terms of Lodash-specific alternatives, you could use other functions like `_.map()`, `_.reduce()`, or `_.compact()` to achieve similar results, but these would likely have different performance characteristics and trade-offs compared to `_.sortBy` and `_.orderBy`.
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?