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>
var alpha = function(){ return true };
var defaultFunc = function(){ return false };
var switchByObj = (function(){
var noop = function(){},
switchObj = {
foo: noop,
bar: noop,
steins: noop,
gate: noop,
mad: noop,
scientist: noop,
alpha: alpha
};
var _default = defaultFunc;
return function(arg){
(switchObj[arg] || _default)();
};
})();
// called by switch
var switchBySwitch = function(arg){
switch (arg) {
case 'foo': break;
case 'bar': break;
case 'steins': break;
case 'gate': break;
case 'mad': break;
case 'scientist': break;
case 'alpha':
alpha();
break;
default:
defaultFunc();
}
};
var switchByIfElse = function(arg){
if(arg == 'foo'){
}
else if(arg == 'bar'){
}
else if(arg == 'steins'){
}
else if(arg == 'gate'){
}
else if(arg == 'mad'){
}
else if(arg == 'scientist'){
}
else if(arg == 'alpha'){
alpha();
}
else {
defaultFunc();
}
};
var switchByIfReturn = function(arg){
if(arg == 'foo'){
return;
}
if(arg == 'bar'){
return;
}
if(arg == 'steins'){
return;
}
if(arg == 'gate'){
return;
}
if(arg == 'mad'){
return;
}
if(arg == 'scientist'){
return;
}
if(arg == 'alpha'){
return alpha();
}
return defaultFunc();
};
var switchByCombinedIf = function(arg){
if(arg == 'foo' || arg == 'bar' || arg == 'steins' || arg == 'gate' || arg == 'mad' || arg == 'scientist'){
return;
}
if (arg == 'alpha'){
return alpha();
}
return defaultFunc();
};
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
switch: hit |
| ready |
switch: miss |
| ready |
switchObj: hit |
| ready |
switchObj: miss |
| ready |
if-else: hit |
| ready |
if-else: miss |
| ready |
if-return: hit |
| ready |
if-return: miss |
| ready |
if-combined-return: hit |
| ready |
if-combined-return: miss |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.