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
<script>
function getDrink1(type) {
switch (type) {
case 'coke':
type = 'Coke';
break;
case 'pepsi':
type = 'Pepsi';
break;
case 'lemonade':
type = 'Lemonade';
break;
}
return type;
}
function getDrink2(type) {
if (type === 'coke') {
type = 'Coke';
} else if (type === 'pepsi') {
type = 'Pepsi';
} else if (type === 'lemonade') {
type = 'Lemonade';
}
return type;
}
function getDrink3(type) {
var drinks = {
'coke': 'Coke',
'pepsi': 'Pepsi',
'lemonade': 'Lemonade'
};
return drinks[type];
}
function getDrink4(type) {
return {
'coke': 'Coke',
'pepsi': 'Pepsi',
'lemonade': 'Lemonade'
}[type];
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
switch |
| ready |
if else |
| ready |
object literal 1 |
| ready |
object literal 2 |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.