Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash sortBy vs orderBy fixed 4.17.11
(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.11/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 dive into the world of microbenchmarks. **What is tested?** The provided JSON represents two benchmark test cases for comparing the performance of Lodash's `sortBy` and `orderBy` functions. Both tests aim to measure how efficiently these functions sort an array of objects based on a specific property (`value`) in JavaScript. **Options compared:** Two options are being compared: 1. **Lodash `sortBy`**: This function sorts the array in ascending order by the value property. 2. **Lodash `orderBy`**: This function sorts the array in descending order by the value property. **Pros and Cons of each approach:** * **Lodash `sortBy`**: * Pros: * Can sort arrays in both ascending and descending orders using different methods (e.g., `.sortBy()` for ascending, `.orderBy()` for descending). * Supports sorting based on multiple properties. * Cons: * May perform slower than native JavaScript sorting methods due to the overhead of the Lodash library. * **Lodash `orderBy`**: * Pros: * Specifically designed for sorting in descending order, which can be more efficient than using `.sortBy()` and then reversing the result. * Can sort arrays in both ascending and descending orders using different methods (e.g., `.sort((a, b) => b.value - a.value)`). * Cons: * Only supports sorting based on a single property. **Other considerations:** * Both `sortBy` and `orderBy` functions use the `Array.prototype.sort()` method under the hood, which has a time complexity of O(n log n). However, Lodash may introduce additional overhead due to its library code. * The choice between `sortBy` and `orderBy` ultimately depends on the specific requirements of your application. If you need more control over the sorting process or want to sort arrays in multiple ways, `.sortBy()` might be a better option. **Library:** The Lodash library is used in both benchmark test cases. Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks such as string manipulation, array manipulation, and object manipulation. **Special JS feature/syntax:** None mentioned in the provided JSON, but it's worth noting that some features like `async/await` or `promises` are not typically used in microbenchmarking, as they can introduce additional overhead due to context switching. In this case, both benchmark test cases use synchronous code. **Alternatives:** If you prefer native JavaScript methods over Lodash, you can implement the sorting logic using the following methods: * For ascending order: `arr.sort((a, b) => a.value - b.value)` * For descending order: `arr.sort((a, b) => b.value - a.value)`
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?