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
A quick test of the performance of returning early in a method vs storing a returnValue and returning the value at the end of the method
function earlyReturn(val) {
if (val === undefined) {
return 'It is undefined';
}
if (val === null) {
return 'It is null';
}
return 'It has something';
}
function singleReturn(val) {
var retValue;
if (val === undefined) {
retValue = 'It is undefined';
} else if (val === null) {
retValue = 'It is null';
} else {
retValue = 'It has something';
}
return retValue;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
early return |
| ready |
single return |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.