call vs apply (v37)

Revision 37 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 that = {that: "that"};
    var arg = "arg";
    var arg_array = [arg];
    var arg_array2 = [arg, arg];
    var arg_array3 = [arg, arg, arg];
    var arg_array4 = [arg, arg, arg, 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
apply 2
Obj.prototype.target.apply(that, arg_array2);
ready
call 2
Obj.prototype.target.call(that, arg, arg);
ready
call 3
Obj.prototype.target.call(that, arg, arg, arg);
ready
call 4
Obj.prototype.target.call(that, arg, arg, arg, arg);
ready
apply 3
Obj.prototype.target.apply(that, arg_array3);
ready
apply 4
Obj.prototype.target.apply(that, arg_array4);
ready

Revisions

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