function calls: direct vs apply vs call vs bind

JavaScript performance comparison

Revision 86 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function f() {
      return this;
  }
  var that = {
      f: f
  };
  var bound = f.bind(that);
  var that2 = Object.create(that);
  var that3 = {};
  var that4 = Object.create(that3);
  function A() {
      this.bar = "bar";
  }
  A.prototype.foo = function () {
      return this.bar;
  }
  function B () {
  }
  B.prototype = Object.create(A.prototype);
  B.prototype.constructor = B;
  var b = new B();
  var bound = A.prototype.foo.bind(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
call
A.prototype.foo.call(b);
pending…
bind
var newBound = A.prototype.foo.bind(b);
newBound();
pending…
bound
bound();
pending…
bind
bound();
pending…
prototype
that2.f();
pending…
direct (dynamic property)
that3.f = f; that3.f();
pending…
prototype (dynamic property)
that3.f = f; that4.f();
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