function calls: direct vs apply vs call vs bind

JavaScript performance comparison

Revision 71 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function f(){
    return this;
  };
  
  function bind (self, fn) {
      
      return function () {
          return fn.apply(self, arguments);
      };
  }
  
  function wrapped () {
      return f();
  }
  
  function cBind (self, fn) {
      
      return function (callback) {
          return fn.call(self, callback);
      };
  }
  
  var that = {};
  
  var bound = f.bind(that);
  
  var cBound = bind(that, f);
  var ccBound = cBind(that, f);

};
</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
direct
f();
pending…
apply
f.apply(that);
pending…
call
f.call(that);
pending…
bind
bound();
pending…
custom bind
cBound();
pending…
custom bind 2
ccBound();
pending…
wrapped
wrapped();
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