return vs no return

JavaScript performance comparison

Revision 7 of this test case created

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.

Testing in unknown unknown
Test Ops/sec
noReturn
noReturn(42);
pending…
doesReturn
doesReturn(42);
pending…
doesValuelessReturn
doesValuelessReturn(42);
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:

1 comment

Fylhan commented :

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.

Add a comment