return vs no return
JavaScript performance comparison
Info
How much does returning a value slow a function down?
Preparation code
<script>
function callback(val) {
//val++;
}
function noReturn(val) {
val = val - 0;
}
function doesReturn(val) {
val = val - 0;
return callback(val);
}
function doesValuelessReturn(val) {
val = val - 0;
callback(val);
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… |
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
1 comment
That is what I thought: the "val++;" was done in "doesReturn" and "doesValuelessReturn" but not in "noReturn". I just comment this line, and we have now a more correct result: they are all as fastest.