return vs no return
JavaScript performance comparison
Info
How much does returning a value slow a function down?
Preparation code
<script>
function noReturn(err, callback) {
if (err) {
callback('error');
} else {
callback(null, 'value');
}
}
function doesReturn(err, callback) {
if (err) {
return callback('error');
}
return callback(null, 'value');
}
function doesValuelessReturn(err, callback) {
if (err) {
callback('error');
} else {
callback(null, 'value');
return;
}
}
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
noReturn |
|
pending… |
doesReturn |
|
pending… |
doesValuelessReturn |
|
pending… |
noReturn.err |
|
pending… |
doesReturn.err |
|
pending… |
doesValuelessReturn.err |
|
pending… |
Compare results of other browsers
Revisions
You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:
- Revision 1: published by Alexis Deveria
- Revision 3: published
- Revision 4: published
- Revision 5: published
- Revision 6: published by max jooher
- Revision 7: published
- Revision 8: published by fencliff
- Revision 9: published and last updated
0 comments