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
Checks whats faster between a switch case and an array
str = 'dog'
function switchTest(){
switch(str){
case 'cat':
return true;
break;
case 'mouse':
return true;
break;
case 'parrot':
return true;
break;
case 'monkey':
return true;
break;
case 'dog':
return true;
break;
default: break; return false ;
}
}
a = {
'cat': true,
'mouse': true,
'parrot': true,
'monkey': true,
'dog': true
}
function arrayTest(){
return a[str] || false;
}
var b = ['cat','mouse','parrot','monkey','dog'];
function indexOfTest(){
return ['true','true','true','true','true'][b.indexOf(str)];
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Array Lookups |
| ready |
Switch Case Loops |
| ready |
indexOf Loops |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.