Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36
Chrome 53
Mac OS X 10.10.5
Other
8 years ago
Test name Executions per second
Sort the sorted 3066.3 Ops/sec
Sort the shuffled 2980.2 Ops/sec
Script Preparation code:
x
 
function shuffle(array) {
  var currentIndex = array.length, temporaryValue, randomIndex;
  // While there remain elements to shuffle...
  while (0 !== currentIndex) {
    // Pick a remaining element...
    randomIndex = Math.floor(Math.random() * currentIndex);
    currentIndex -= 1;
    // And swap it with the current element.
    temporaryValue = array[currentIndex];
    array[currentIndex] = array[randomIndex];
    array[randomIndex] = temporaryValue;
  }
  return array;
}
var sorted = [];
var shuffled = [];
for (var i = 0; i < 1000; i++) {
  sorted.push('a' + i);
  shuffled.push('a' + i);
}
shuffled = shuffle(shuffled);
Tests:
  • Sort the sorted

     
    var s2 = sorted.sort();
  • Sort the shuffled

     
    var s2 = shuffled.sort();