function calls: direct vs apply vs call vs bind

JavaScript performance comparison

Revision 93 of this test case created by pusha

Preparation code

<script>
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.bound(obj);
var fw = function () {
  obj.f(1);
};
</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