call vs apply (v66)

Revision 66 of this benchmark created by AJ ONeal on


Setup

function Obj() {
      var that = "that";
    }
    Obj.prototype.target = function(arg) {
      var string = "that: " + this.that + ", arg: " + arg;
      return string;
    };
    var that = {that: "that"};
    var arg = "arg";
    var arg_array = [arg];
    var obj = { target: Obj.prototype.target };
    var inst = new Obj();

Test runner

Ready to run.

Testing in
TestOps/sec
Call
Obj.prototype.target.call(that, arg);
ready
Apply
Obj.prototype.target.apply(that, arg_array);
ready
call.apply
Function.call.apply(Obj.prototype.target, that, arg_array);
ready
invoke instance
inst.target(arg_array);
ready
invoke non-instance
obj.target = Obj.prototype.target;
obj.target(arg_array);
ready

Revisions

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