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
// if-else
function getOrderMessage1(status) {
if (status === 'pending') {
return 'Order is pending.';
} else if (status === 'shipped') {
return 'Order has been shipped.';
} else if (status === 'delivered') {
return 'Order has been delivered.';
}
}
// object with string keys
const orderMessages2 = {
'pending': 'Order is pending.',
'shipped': 'Order has been shipped.',
'delivered': 'Order has been delivered.',
};
function getOrderMessage2(status) {
return orderMessages2[status];
}
// object with number keys (similar to enum)
const orderMessages3 = {
0: 'Order is pending.',
1: 'Order has been shipped.',
2: 'Order has been delivered.',
};
function getOrderMessage3(status) {
return orderMessages3[status];
}
// switch-case
function getOrderMessage4(status) {
switch (status) {
case 'pending':
return 'Order is pending.';
case 'shipped':
return 'Order has been shipped.';
case 'delivered':
return 'Order has been delivered.';
default:
return 'Unknown order status.';
}
}
Ready to run.
Test | Ops/sec | |
---|---|---|
if |
| ready |
object with string keys |
| ready |
object with numbered keys |
| ready |
switch-case |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.