Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash Orderby
(version: 0)
lodash orderby vs Js Sort
Comparing performance of:
Lodash orderby vs Js sortByDesc
Created:
6 years ago
by:
Registered User
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:
Lodash orderby
_.orderBy(arr, ['value'], ['desc']);
Js sortByDesc
function sortByDesc(key) { return (a, b) => (a[key] < b[key]) ? 1 : ((b[key] < a[key]) ? -1 : 0); }; arr.concat().sort(sortByDesc('value'))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash orderby
Js sortByDesc
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Browser/OS:
Chrome 130 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash orderby
27.0 Ops/sec
Js sortByDesc
54.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and its test cases. **Benchmark Definition** The benchmark is comparing two approaches to sorting an array of objects in descending order: Lodash's `orderBy` function and a custom implementation using JavaScript's built-in `sort()` method with a custom comparison function. **Options Compared** The benchmark is testing two options: 1. **Lodash's `orderBy` function**: This function takes an array, a key path, and an order parameter (in this case, `'desc'`). It returns the sorted array. 2. **Custom implementation using JavaScript's built-in `sort()` method with a custom comparison function**: This approach uses the `sort()` method to sort the array, providing a custom comparison function that compares two objects based on their values. **Pros and Cons** Here are some pros and cons of each approach: * **Lodash's `orderBy` function**: + Pros: Convenient and easy to use, especially for complex sorting scenarios. + Cons: Adds extra overhead due to the library itself, and may not be optimized for specific use cases. * **Custom implementation using JavaScript's built-in `sort()` method with a custom comparison function**: + Pros: Lightweight and optimized for specific use cases, allowing for fine-grained control over the sorting process. + Cons: Requires more code and manual effort to set up, which can be error-prone. **Library Used** The benchmark uses Lodash.js, a popular JavaScript utility library that provides various functions for tasks such as string manipulation, array manipulation, and object manipulation. In this case, the `orderBy` function is used to sort the array. **JavaScript Feature/Syntax** The benchmark does not use any special JavaScript features or syntax. It only relies on standard JavaScript capabilities. **Other Alternatives** If you need a lightweight sorting solution with fine-grained control, consider using other libraries like: * **Sort.js**: A lightweight JavaScript library for sorting arrays. * **Array.prototype.sort() method**: The built-in `sort()` method can be used with custom comparison functions for specific use cases. For more complex sorting scenarios or larger datasets, Lodash's `orderBy` function may still be a good choice due to its convenience and flexibility.
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?