Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36
Chrome 103
Mac OS X 10.15.7
Desktop
2 years ago
Test name Executions per second
_.sortBy 1604973.4 Ops/sec
array.prototype.sort 10343582.0 Ops/sec
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 arr = [];
var EXECUTION_BLOCK_NAMES = ['Итого', 'Центр', 'Урал+Сибирь'];
for(var i = 0; i < 100000; i++){
  arr.concat([{name: 'Итого'}, {name: 'Центр'}, {name: 'Урал+Сибирь'}]);
}
Tests:
  • _.sortBy

     
    _.sortBy(arr, (i) => EXECUTION_BLOCK_NAMES.indexOf(i.name));
  • array.prototype.sort

     
    arr.sort((i) => EXECUTION_BLOCK_NAMES.indexOf(i.name));