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
var dateString = "1992-01-13";
function getAge(dateString) {
var today = new Date();
var birthDate = new Date(dateString);
var age = today.getFullYear() - birthDate.getFullYear();
var m = today.getMonth() - birthDate.getMonth();
if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
age--;
}
return age;
}
function calcAge(dateString) {
var birthday = +new Date(dateString);
return ~~((Date.now() - birthday) / (31557600000));
}
function getDiff(dateString) {
birthday = new Date(dateString);
var now = new Date();
var nowYear = now.getFullYear();
var birthdayYear = birthday.getFullYear();
var birthdayThisYear = new Date(nowYear, birthday.getMonth(), birthday.getDate());
var dif = nowYear - birthdayYear + (birthdayThisYear > now ? -1 : 0);
return dif;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Accepted Answer |
| ready |
Optimized code |
| ready |
3 |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.