call vs apply (v5)

Revision 5 of this benchmark created by gsf on


Setup

function Obj() {
      var that = "that";
    }
    Obj.prototype.target = function(arg) {
      var string = "that: " + this.that + ", arg: " + arg;
      return string;
    };
    
    var myObj = new Obj();

Test runner

Ready to run.

Testing in
TestOps/sec
Call
var that = {that: "that"};
var arg = "arg";
Obj.prototype.target.call(that, arg);
ready
Apply
var that = {that: "that"};
var arg = "arg";
Obj.prototype.target.apply(that, [arg]);
ready
Normal invocation
var arg = "arg";
new Obj().target(arg);
ready
Normal invocation cached Obj
var arg = "arg";
myObj.target(arg);
ready
Call without args
var that = {that: "that"};
var arg = "arg";
Obj.prototype.target.call(that);
ready
Apply without args
var that = {that: "that"};
var arg = "arg";
Obj.prototype.target.apply(that);
ready

Revisions

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