Run details:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36
Chrome 89
Linux
Desktop
3 years ago
Test name Executions per second
sort array of date property inside objects 16.2 Ops/sec
sort array of integers 213.4 Ops/sec
Script Preparation code:
x
 
function randomDate(start, end) {
    return new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
}
var arrObjects = [];
for(var i = 0; i < 100000; i++){
  arrObjects.push({value:randomDate(new Date(2012, 0, 1), new Date())});
}
function getRandomInt(max) {
  return Math.floor(Math.random() * Math.floor(max));
}
var arrIntegers = [];
for(var i = 0; i < 100000; i++){
  arrIntegers.push({value:getRandomInt(100)});
}
Tests:
  • sort array of date property inside objects

     
    arrObjects.sort((a,b) => a.value - b.value);
  • sort array of integers

     
    arrIntegers.sort((a,b) => a.value - b.value);