Spread vs Concat - size agnostic

JavaScript performance comparison

Test case created by meeroslav

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const array1 = [];
  const array2 = [];
  const array3 = [];
  const array4 = [];
  
  for (let i = 0; i < 10; ++i) {
      array1.push(i);
  }
  for (let i = 23; i < 29; ++i) {
      array2.push(i);
  }
  for (let i = 0; i < 10000; ++i) {
      array3.push(i);
  }
  for (let i = 23000; i < 37000; ++i) {
      array4.push(i);
  }

};
</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
Spread
const sum = [ ...array1, ...array2 ];
pending…
Concat
const sum = array1.concat(array2);
pending…
Spread + large array
const sum = [ ...array3, ...array4 ];
pending…
Concat + large array
const sum = array3.concat(array4);
pending…

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

0 Comments