call vs apply (v35)

Revision 35 of this benchmark created on


Setup

function Obj() {
          var that = "that";
    }
    Obj.prototype.target = function(test) {
       return test;
    };
    var yes_array = ["YES"];
    var yes_string = "YES";
    
    var scope = {};
    scope._tmp = Obj.prototype.target;
    
    var that = Obj.prototype;
    var wrapped = function(){
    that.target(yes_string);
    };

Test runner

Ready to run.

Testing in
TestOps/sec
apply
Obj.prototype.target.apply(scope, ["YES"]);  
ready
call
Obj.prototype.target.call(scope, "YES");
ready
apply, existing array
Obj.prototype.target.apply(scope, yes_array);
ready
call, existing string
Obj.prototype.target.call(scope, yes_string);
ready
direct tmp assign - cached
scope._tmp(yes_string);
ready
direct tmp assign
scope.__tmp = Obj.prototype.target;
scope.__tmp(yes_string);
delete scope.__tmp
ready
direct call - just to compare (incorrect)
Obj.prototype.target(yes_string);
ready
wrapped
wrapped();
ready
just apply, without arguments
Obj.prototype.target.apply(scope);
ready
just call, without arguments
Obj.prototype.target.call(scope);
ready

Revisions

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