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
Does returning false
at the end of a function have a performance cost? Can we just rely on undefined
being falsy?
EDIT: The results are surprising. It seems as though returning a value at all has a performance cost, although after conducting another test it appears this assumption is wrong.
var test_even_a = function (i) {
if (i % 2 === 0) return true;
};
var test_even_b = function (i) {
if (i % 2 === 0) return true;
else return false;
};
var test_even_c = function (i) {
return i % 2 === 0;
};
var test_function = function (fn) {
for (var i = 0; i < 1000; i++) {
fn(i);
}
};
Ready to run.
Test | Ops/sec | |
---|---|---|
no return |
| ready |
return false |
| ready |
no if condition |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.