direct v call v apply

JavaScript performance comparison

Revision 3 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var A;
    A = (function() {
      var fn = function(a, b, c) {
          this.a = a;
          this.b = b;
          this.c = c;
          }
         
         
      function A() {}
      A.prototype = {
        fn: function(a, b, c) {
          this.a = a;
          this.b = b;
          this.c = c;
        },
        _direct: function(a, b, c) {
          this.fn(a, b, c);
        },
        _call: function(a, b, c) {
          fn.call(this, a, b, c);
        },
        _apply_array: function(arr) {
          fn.apply(this, arr);
        },
        _apply_arguments: function(a, b, c) {
          fn.apply(this, arguments);
        }
      };
   
      return A;
   
    })();
    var a = 10,
        b = "something",
        c = [10, 20, 30];
    var arr = [a, b, c];
    var inst = new A();
};
</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
Direct
inst._direct(a, b, c);
pending…
Call
inst._call(a, b, c);
pending…
Apply - array
inst._apply_array(arr);
pending…
Apply - arguments
inst._apply_arguments(a, b, c);
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