call vs apply (v38)

Revision 38 of this benchmark created by Mike Frey on


Setup

function Obj() {
      var that = "that";
    }
    Obj.prototype.target = function() {
    };
    
    var myObj = new Obj(),
        that = {that: "that"},
        arg = "arg",
        arg0 = "arg0", arg1 = "1", arg2 = "arg2", arg3 = "arg3", arg4 = "arg4",
        args = (function(){ return arguments; }(arg0, arg1, arg2, arg3, arg4));

Test runner

Ready to run.

Testing in
TestOps/sec
Call
Obj.prototype.target.call(that, arg0, arg1, arg2, arg3, arg4);
ready
Apply
Obj.prototype.target.apply(that, args);
ready
Normal invocation
myObj.target(arg0, arg1, arg2, arg3, arg4);
ready
Call w/ lookup
switch (args.length)  {
    case 5:
        Obj.prototype.target.call(that, args[0], args[1], args[2], args[3], args[4]);
        break;
}
ready
Call w/ lookup complex
switch (args.length)  {
    case 3:
        Obj.prototype.target.call(that, args[0], args[1], args[2]);
        break;
    case 4:
        Obj.prototype.target.call(that, args[0], args[1], args[2], args[3]);
        break;
    case 5:
        Obj.prototype.target.call(that, args[0], args[1], args[2], args[3], args[4]);
        break;
}
ready

Revisions

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