return vs no return

JavaScript performance comparison

Revision 5 of this test case created

Info

How much does returning a value slow a function down?

Preparation code

<script>
  function callback(val) {
   console.log(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:

0 comments

Add a comment