call vs apply (v67)

Revision 67 of this benchmark created by Jose Cabo 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 _target = Obj.prototype.target;
    var _call = Function.call;
    var _bind = Function.bind;
    var arg_array2 = [that, arg];

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
Direct call.apply
_call.apply(_target, that, arg_array);
ready
Direct call
_target.call(that, arg);
ready
Direct apply
_target.apply(that, arg_array);
ready
bind direct
_bind.apply(_target, arg_array2)();
ready

Revisions

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