function calls: direct vs apply vs call vs bind

JavaScript performance comparison

Revision 97 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var f = function(foo, a, b, c){
    return [foo, a, b, c];
  };
  
  var f2 = function(a, b, c) {
    return [this, a, b, c];
  };
  
  var foo = {};
  
  var a = 1, b = 2, c = 3, abc = [1, 2, 3];
  
  var bound = f2.bind(foo);

};
</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(foo, a, b, c);
pending…
apply
f2.apply(foo, abc);
pending…
call
f2.call(foo, a, b, c);
pending…
bind
bound();
pending…
apply2
f2.apply(foo, [a, b, c])
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