call vs apply

JavaScript performance comparison

Revision 3 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function Obj() {
      var that = "that";
    }
    Obj.prototype.target = function(arg) {
      var string = "that: " + this.that + ", arg: " + arg;
      return string;
    };
   
    var myObj = new Obj();
};
</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
Call
var that = {that: "that"};
var arg = "arg";
Obj.prototype.target.call(that, arg);
pending…
Apply
var that = {that: "that"};
var arg = "arg";
Obj.prototype.target.apply(that, [arg]);
pending…
Normal invocation
var arg = "arg";
new Obj().target(arg);
pending…
Normal invocation cached Obj
var arg = "arg";
myObj.target(arg);
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