Function vs. Inline

JavaScript performance comparison

Revision 11 of this test case created by

Preparation code

<script>
  runs = 1000;
  var testerFunctionReduced = function(i) {
   return runs + i;
  }
  var testerFunctionFlat = function(i) {
    var a = runs + i;
    a = a * a;
    a = a * 2;
    return a;
    //return (runs + i * runs + i) * 2;
  }
  var testerFunctionNested3 = function(i) {
   return i*2;
  }
  var testerFunctionNested2 = function(i) {
   return testerFunctionNested3(i * i);
  }
  var testerFunctionNested = function(i) {
   var a = runs + i;
   return testerFunctionNested2(a);
  }
</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 single
for (var i = 0; i < runs; i++) {
 var a = testerFunctionFlat(i);
}
pending…
inline single
var a;

for (var i = 0; i < runs; i++) {
   a = runs + i;
   a = a * a;
   a = a * 2;
}
pending…
function call nested
for (var i = 0; i < runs; i++) {
 var a = testerFunctionNested(i);
}
pending…
function call reduced
for (var i = 0; i < runs; i++) {
 var a = testerFunctionReduced(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