Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash orderBy vs Array.sort 50 000 elements
(version: 1)
Sort and array of objects by 2 properties : - text: descending - id: ascending
Comparing performance of:
_.orderBy vs Array.sort
Created:
one year 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:
var generateText = function(){ return Math.random().toString(36).substring(2, 4); } var arr = [] for(i=0; i<50000; i++){ const obj = {} obj.id = i; obj.text = generateText() arr.push(obj) }
Tests:
_.orderBy
_.orderBy(arr, ['text', 'id'], ['desc', 'asc'])
Array.sort
arr.sort((a, b) => (a.text < b.text) ? 1 : (a.text === b.text) ? ((a.id > b.id) ? 1 : -1) : -1 )
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
_.orderBy
Array.sort
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
10 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Browser/OS:
Chrome 137 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
_.orderBy
39.9 Ops/sec
Array.sort
1447.1 Ops/sec
Autogenerated LLM Summary
(model
gpt-4o-mini
, generated one year ago):
The benchmark defined in the provided JSON tests two different sorting methods for an array of objects containing 50,000 elements. The elements are sorted based on two properties: `text` (in descending order) and `id` (in ascending order). The two sorting methods being compared are: 1. **Lodash's `_.orderBy`** 2. **Native JavaScript's `Array.sort`** ### Options Compared 1. **Lodash `_.orderBy`:** - This method is a utility function provided by the Lodash library, which facilitates functional programming in JavaScript. - `_.orderBy(arr, ['text', 'id'], ['desc', 'asc'])` specifies the `arr` to be sorted, along with an array of property names (`text`, `id`) and their respective sorting orders (`desc`, `asc`). 2. **Native JavaScript `Array.sort
Related benchmarks:
Lodash orderBy vs array.prototype.sort new array
SortBy vs Arr.Sort
Lodash sortBy vs Object.values and array.prototype.sort
lodash orderBy vs Array.sort
Lodash sort vs array.prototype.sort with localeCompare
Lodash sort vs array.prototype.sort for objects with strings
lodash orderBy vs Array.sort on single key
Lodash sort vs array.prototype.sort strings
_.sortBy vs _.orderBy vs JS sort multiple
Comments
Confirm delete:
Do you really want to delete benchmark?