Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36
Chrome 119
Mac OS X 10.15.7
Desktop
one year ago
Test name Executions per second
localeCompare 138615.0 Ops/sec
lodash order 40312.3 Ops/sec
sort comparator 52630.3 Ops/sec
HTML Preparation code:
AخA
 
1
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
 
function shuffle(array) {
    var i = array.length,
        j = 0,
        temp;
    while (i--) {
        j = Math.floor(Math.random() * (i + 1));
        temp = array[i];
        array[i] = array[j];
        array[j] = temp;
    }
    return array;
}
var words = ["aaa", "bbb", "ccc", "AAA", "BBB", "CCC", "123", "234", "345", "aaa", "bbb", "ccc", "AAA", "BBB", "CCC", "123", "234", "345", "aaa", "bbb", "ccc", "AAA", "BBB", "CCC", "123", "234", "345", "aaa", "bbb", "ccc", "AAA", "BBB", "CCC", "123", "234", "345", "가나다", "나다라", "마바사"];
var words1 = [];
var n = [];
for (i = 0; i < 4; i++) words.push(...words);
for (i = 0; i < words.length; i++) n.push(i);
var ranNums = shuffle(n);
for (i = 0; i < words.length; i++) words1.push(words[ranNums[i]]);
console.log('ORIGINAL', words1);
Tests:
  • localeCompare

     
    words1.sort((a,b) => a.localeCompare(b));
  • lodash order

     
    _.orderBy(words1,model => model,'asc');
  • sort comparator

     
    words1.sort((a,b) => {
      if (a.toLowerCase() < b.toLowerCase()) {
        return -1;
      }
      if (a.toLowerCase() > b.toLowerCase()) {
        return 1;
      }
      return 0;
    });