Function vs. Inline

JavaScript performance comparison

Test case created by Mike Grace and last updated

Preparation code

<script>
  runs = 1000;
  var testerFunction = function(i) {
   return runs + i;
  }
  var testerFunction2 = function(i) {
   var a = runs + i;
   return a * 2;
  }
</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 = testerFunction(i);
}
pending…
inline single
for (var i = 0; i < runs; i++) {
 var a = runs + i;
}
pending…
function call double
for (var i = 0; i < runs; i++) {
 var a = testerFunction2(i);
}
pending…
inline double
for (var i = 0; i < runs; i++) {
 var a = runs + i;
 a = a * 2;
}
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