HTML Preparation code:
x
 
1
2
<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<100; 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>

Previous results

Experimental features:

  • Test case name Result
    _.orderBy
    Array.sort

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 15 days ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0
Chrome 134 on Windows
View result in a separate tab
Test name Executions per second
_.orderBy 22169.0 Ops/sec
Array.sort 342042.1 Ops/sec