call vs apply (v80)

Revision 80 of this benchmark created 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";
var a = [arg];
Obj.prototype.target.apply(that, a);
ready
Normal invocation
var arg = "arg";
new Obj().target(arg);
ready
Normal invocation cached Obj
var arg = "arg";
myObj.target(arg);
ready

Revisions

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