function calls: direct vs apply vs call vs bind

JavaScript performance comparison

Revision 94 of this test case created by

Preparation code

<script>

</script>

      
<script>
Benchmark.prototype.setup = function() {
  function Entity(x) {
    this.x = x;
  }
  
  Entity.prototype.f = function(y) {
    return this.x * y;
  };
  
  var obj = new Entity(42);
  var fc = Entity.prototype.f;
  var fb = Entity.prototype.f.bind(obj);
  var fw = function (y) {
    obj.f(y);
  };

};
</script>

Preparation code output

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
direct
obj.f(1);
pending…
call
fc.call(obj, 1);
pending…
bind
fb(1);
pending…
wrap
fw(1);
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