HTML Preparation code:
x
 
1
2
<script src='https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js'></script>
3
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
 
let fruits = [
  {name:"mango", amount: 1},
  {name:"apple", amount: 4},
  {name:"banana", amount: 2},
  {name:"pineapple", amount: 2},
  {name:"apple", amount: 2}
]
const sortBy = (key) => {
  return (a, b) => (a[key] > b[key]) ? 1 : ((b[key] > a[key]) ? -1 : 0);
};
fruits.sort(sortBy("name"));
Tests:
  • Lo-Dash sortBy()

     
    let fruits = [
      {name:"mango", amount: 1},
      {name:"apple", amount: 4},
      {name:"banana", amount: 2},
      {name:"pineapple", amount: 2},
      {name:"apple", amount: 2}
    ]
    _.sortBy(fruits, 'name')
  • Underscore sortBy()

     
    let fruits = [
      {name:"mango", amount: 1},
      {name:"apple", amount: 4},
      {name:"banana", amount: 2},
      {name:"pineapple", amount: 2},
      {name:"apple", amount: 2}
    ]
    _.sortBy(fruits, 'name')
  • Vanilla sort()

     
    let fruits = [
      {name:"mango", amount: 1},
      {name:"apple", amount: 4},
      {name:"banana", amount: 2},
      {name:"pineapple", amount: 2},
      {name:"apple", amount: 2}
    ]
    const sortBy = (key) => {
      return (a, b) => (a[key] > b[key]) ? 1 : ((b[key] > a[key]) ? -1 : 0);
    };
    fruits.sort(sortBy("name"));
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Lo-Dash sortBy()
    Underscore sortBy()
    Vanilla sort()

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 55 minutes 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
Lo-Dash sortBy() 1258222.4 Ops/sec
Underscore sortBy() 1256008.1 Ops/sec
Vanilla sort() 4037743.0 Ops/sec