Test name | Executions per second |
---|---|
sort array of date property inside objects | 16.2 Ops/sec |
sort array of integers | 213.4 Ops/sec |
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)});
}
arrObjects.sort((a,b) => a.value - b.value);
arrIntegers.sort((a,b) => a.value - b.value);