call vs apply vs plain function

JavaScript performance comparison

Revision 18 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function Obj() {
          var that = "that";
    }
    Obj.prototype.target = function(test) {
       return test;
    };
    var funcName = "target";
    var inObj = new Obj();
    var arr = ["YES"];
    var fn = function(test) {
       return test;
    };
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
no context prototype apply
Obj.prototype.target.apply(null, ["YES"]);  
pending…
no context prototype call
Obj.prototype.target.call(null, "YES");
pending…
object function call
inObj.target('YES');
pending…
with context plain function apply
fn.apply(inObj, ["YES"]);  
pending…
no context plain function apply arr
fn.apply(null, arr);  
pending…
no context plain function call
fn.call(null, "YES");  
pending…
with context prototype apply
Obj.prototype.target.apply(inObj, ["YES"]);  
pending…
with context prototype call
Obj.prototype.target.call(inObj, "YES");
pending…
plain function
fn("YES");
pending…
with context plain function call
fn.call(inObj, "YES");
pending…
bracket context
inObj[funcName]("YES");
pending…
bracket context call
inObj[funcName].call(inObj, "YES");
pending…
bracket context apply
inObj[funcName].apply(inObj, ["YES"]);
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment