call vs apply (v78)

Revision 78 of this benchmark created on


Setup

function Obj() {
      var that = "that";
    }
    Obj.prototype.target = function() {
      var string = "that: " + this.that + ", arg: " + arguments;
      return string;
    };

Test runner

Ready to run.

Testing in
TestOps/sec
Call
var obj = new Obj();
var arg1 = "arg1";
var arg2 = "arg2";
var arg3 = {name:"arg3"};
var arg4 = {name:"arg4"};
var arg5 = {name:"arg5"};
var args = [arg1, arg2, arg3, arg4, arg5];
if (args.length >= 4)
Obj.prototype.target.call(obj, arg1, arg2, arg3, arg4, arg5);
ready
Apply
var obj = new Obj();
var arg1 = "arg1";
var arg2 = "arg2";
var arg3 = {name:"arg3"};
var arg4 = {name:"arg4"};
var arg5 = {name:"arg5"};
var args = [arg1, arg2, arg3, arg4, arg5];
if (args.length >=4)
Obj.prototype.target.apply(obj, args);
ready
Normal invocation
var obj = new Obj();
var arg1 = "arg1";
var arg2 = "arg2";
var arg3 = {name:"arg3"};
var arg4 = {name:"arg4"};
var arg5 = {name:"arg5"};
var args = [arg1, arg2, arg3, arg4, arg5];
if (args.length >=4)
obj.target(arg1, arg2, arg3, arg4, arg5);
ready

Revisions

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