Cost of a function-invocation

JavaScript performance comparison

Test case created by Shane O'Sullivan

Info

Measures the cost of calling a function over not calling it

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function addition(num) {
      return num + 1;
    }
   
    function additionWithNoParams() {
      count++;
    }
   
    function lazyGitWhoDoesNothing() {
   
    }
   
    var count = 0;
    var iterations = 1000;
};
</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
Without function
for (var i = 0; i < iterations; i++) {
  count = count + 1;
}
pending…
With function
for (var i = 0; i < iterations; i++) {
  count = addition(count);
}
pending…
With function, no params
for (var i = 0; i < iterations; i++) {
  additionWithNoParams();
}
pending…
A no operation function
for (var i = 0; i < iterations; i++) {
  lazyGitWhoDoesNothing();
  count = count + 1;
}
 
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment