Calling function vs apply with arguments

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var functionHeadSimple = function() {
      return 5;
    }
   
    var functionHeadAdvanced = function(a, b, c, d, e, f, g, h) {
      return a + b + c + d + e + f + g + h;
    }
};
</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
Function call without any arguments
var functionSimpleCall = function() {
  return functionHeadSimple();
}

functionSimpleCall();
pending…
Function call with a lot of arguments
var functionAdvancedCall = function(a, b, c, d, e, f, g, h) {
  return functionHeadAdvanced(a, b, c, d, e, f, g, h);
}

functionAdvancedCall(1, 2, 3, 4, 5, 6, 7, 8);
pending…
Function with apply (no arguments)
var functionSimpleApply = function() {
  return functionHeadSimple.apply(this, arguments);
}

functionSimpleApply();
pending…
Function with apply (a lot of arguments)
var functionAdvancedCall = function(a, b, c, d, e, f, g, h) {
  return functionHeadAdvanced.apply(this, arguments);
}

functionAdvancedCall(1, 2, 3, 4, 5, 6, 7, 8);
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