Function calls with spread vs call vs apply

JavaScript performance comparison

Test case created by mcharytoniuk

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var numbers = [1, 2, 3, 4];
  
  function test(a, b, c, d) {
    return a + b + c + d;
  }

};
</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
Default invocation
test(numbers[0], numbers[1], numbers[2], numbers[3]);
pending…
.call
test.call(null, numbers[0], numbers[1], numbers[2], numbers[3]);
pending…
.apply
test.apply(null, numbers);
pending…
spread
test(...numbers);
pending…

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL.

0 Comments