Function vs. Inline

JavaScript performance comparison

Revision 10 of this test case created by sansegot

Preparation code

<script>
var runs = 1000,
  curr = 500,
  min = 1000,
  minX = 1000,
  popis = [],
  popisX = [];

  var testerFunction2 = function(i) {
    if(i>curr) {
      if(i===min) {
        popis.push(i);
      } else if(i < min) {
        min = i;
        popis = [i];
      }
      if(i===minX) {
        popisX.push(i);
      } else if(i < minX) {
        minX = i;
        popisX = [i];
      }
    }
  }
</script>
    

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
function call double
for (var i = 0; i < runs; i++) {
 var a = testerFunction2(i);
}
pending…
inline double
for (var i = 0; i < runs; i++) {
    if(i>curr) {
      if(i===min) {
        popis.push(i);
      } else if(i < min) {
        min = i;
        popis = [i];
      }
      if(i===minX) {
        popisX.push(i);
      } else if(i < minX) {
        minX = i;
        popisX = [i];
      }
    }
}
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.

0 Comments