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 getDiscountA(category) {
let discount;
if (category === "student") {
discount = 20;
} else if (category === "senior") {
discount = 30;
} else if (category === "military") {
discount = 25;
} else {
discount = 0;
}
return discount;
}
function getDiscountAEaryReturn(category) {
if (category === "student") {
return 20;
} else if (category === "senior") {
return 30;
} else if (category === "military") {
return 25;
}
return 0;
}
function getDiscountB(category) {
return {
"student": 20,
"senior": 30,
"military": 25
}[category] || 0;
}
const discounts = {
student: 20,
senior: 30,
military: 25
};
function getDiscountC(category) {
return discounts[category] ?? 0;
}
const discountsMap = new Map([
["student", 20],
["senior", 30],
["military", 25],
]);
function getDiscountCMapped(category) {
return discountsMap.get(category) ?? 0;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
getDiscountA() |
| ready |
getDiscountAEaryReturn() |
| ready |
getDiscountB() |
| ready |
getDiscountC() |
| ready |
getDiscountCMapped() |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.