function calls: direct vs apply vs call vs bind

JavaScript performance comparison

Revision 84 of this test case created by Marc

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var f = function(a, b) {
    return this.v + a + b;
  };
  
  var instance = {
    f: f,
    v: 5,
    r: function (a,b) {
      this.f(a,b);
    },
    t: function (a,b){
      f.call(this, a, b);
    }
  };

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Test 1: direct
instance.f(100, 1000);
pending…
Test 1: call
f.call(instance, 100, 1000);
pending…
Test 2: Internal prototype
instance.r(100, 1000);
pending…
Test 2: Internal call
instance.t(100, 1000);
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.

0 Comments