Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36
Chrome 103
Windows
Desktop
2 years ago
Test name Executions per second
JS spread 14017842.0 Ops/sec
JS Concat 5120028.0 Ops/sec
Avoiding 32496372.0 Ops/sec
Tests:
  • JS spread

    AخA
     
    const arr1 = [ 1,2,3 ];
    const arr2 = [ 4,5,6 ];
    function sum(arr){ return arr.reduce((prev, curr) => prev + curr, 0); }
    sum([...arr1,...arr2]);
  • JS Concat

     
    const arr1 = [ 1,2,3 ];
    const arr2 = [ 4,5,6 ];
    function sum(arr){ return arr.reduce((prev, curr) => prev + curr, 0); }
    sum(arr1.concat(arr2));
  • Avoiding

     
    const arr1 = [ 1,2,3 ];
    const arr2 = [ 4,5,6 ];
    function sum(arr){ return arr.reduce((prev, curr) => prev + curr, 0); }
    sum(arr1) + sum(arr2);