jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
function generateObjectsWithDates(count) {
count = count || 10000;
var objects = [];
var now = new Date();
for (var i = 0; i < count; i++) {
objects.push({
id: i,
date: new Date(now.getTime() - (i * 24 * 60 * 60 * 1000)),
name: "Object " + i,
value: Math.random() * 100
});
}
return objects;
}
// Generate array of 10,000 objects with Date property
function generateObjectsWithDateStrings(count) {
count = count || 10000;
var objects = [];
var now = new Date();
for (var i = 0; i < count; i++) {
var dateObj = new Date(now.getTime() - (i * 24 * 60 * 60 * 1000));
objects.push({
id: i,
date: dateObj.toISOString(), // Convert to ISO string
name: "Object " + i,
value: Math.random() * 100
});
}
return objects;
}
function sortFunction(a, b) {
var dateA = new Date(a.date).getTime();
var dateB = new Date(b.date).getTime();
return dateA > dateB ? 1 : -1;
}
// Create the test data
var arrayWithDateProps =
generateObjectsWithDates(10);
var arrayWithDateStringProps = generateObjectsWithDates(10);
function sortFunction(a, b) {
var dateA = new Date(a.date).getTime();
var dateB = new Date(b.date).getTime();
return dateA > dateB ? 1 : -1;
}
Ready to run.
| Test | Ops/sec | |
|---|---|---|
| using sortFunction which creates new Date for each sort | | ready |
| Using arrow sort which calls getTime of the date object to use for sorting | | ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.