call vs apply

JavaScript performance comparison

Revision 14 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 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
apply
Obj.prototype.target.apply(this, ["YES"]);  
pending…
call
Obj.prototype.target.call(this, "YES");
pending…
normal
inObj.target( 'YES' );
pending…
Fn Apply
fn.apply(this, ["YES"]);  
pending…
Fn Apply Arr
fn.apply(this, arr);  
pending…
Fn Call
fn.call(this, "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