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
When a function has an arbitrary number of arguments, is it better to check arguments.length (which may have a performance penalty) or to check the presence of an argument (an assumption is that the argument will be 'truthy' if it is present - this can be modified for other purposes).
Both tests include the arguments variable within them, but for one of the functions, arguments will only be sometimes used; the other function always uses it.
function checkArgsLength(arg1){
if (arguments.length > 1){
return doSomething.apply(null, arguments);
}
return false;
}
function checkArgPresence(arg1, arg2){
if (arg2){
return doSomething.apply(null, arguments);
}
return false;
}
function doSomething(arg1){
return window.something = arg1;
}Ready to run.
| Test | Ops/sec | |
|---|---|---|
| arguments.length | | ready |
| argument presence | | ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.