function calls: direct vs apply vs call vs bind

JavaScript performance comparison

Revision 27 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var f = function(){
      return this.x + this.y;
    };
   
    var that = { x: 2, y: 2, ff: f };
   
    var bound = f.bind(that);
   
    var bound2 = function(){
    f.call(that);
    };
};
</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
direct
that.ff();
pending…
apply
f.apply(that);
pending…
call
f.call(that);
pending…
bind
bound();
pending…
direct2
f(that);
pending…
bind2
bound2()
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