direct v call v apply

JavaScript performance comparison

Test case created by Byron

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: function(a, b, c) {
          fn.apply(this, [a, b, c]);
        }
      };
   
      return A;
   
    })();
    var a = 10,
        b = "something",
        c = [10, 20, 30];
};
</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
(new A())._direct(a, b, c);
pending…
Call
(new A())._call(a, b, c);
pending…
Apply
(new A())._apply(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