function calls: direct vs apply vs call vs bind

JavaScript performance comparison

Revision 111 of this test case created by Grzegorz Michlicki

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const f = function(a, b, c) {
  this.a = a;
  this.b = b;
  this.c = c;
      return this;
  };
  
  const that = { f };
  
  let param1 = 1;
  let param2 = 2;
  let param3 = 3;
  const params = [param1, param2, param3];
  
  

};

Benchmark.prototype.teardown = function() {
  param1 += 1;
  param2 += 1;
  param3 += 1;

};
</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 spread
f.call(that, ...params);
pending…
apply
f.apply(that, params);
pending…
call
f.call(that, param1, param2, param3);
pending…
direct spread
that.f(...params);
pending…
direct
that.f(param1, param2, param3);
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