HTML Preparation code:
x
 
1
2
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
 
var existing = [ 1, 2, "hello", true, 7 ];
var newi = [1, 1, 1];
Tests:
  • Array.prototype.concat

     
    var other = existing.concat(newi);
  • spread operator

     
    var other = [ ...existing, ...newi ];
  • copy on push

     
    var other = newi.forEach(i => existing.concat().push(i));
  • directly push

     
    newi.forEach(i => existing.push(i));
  • flat

     
    var other = _.flatten([ existing, newi ]);
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Array.prototype.concat
    spread operator
    copy on push
    directly push
    flat

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 3 years ago)
Mozilla/5.0 (Linux; Android 11; HD1907) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Mobile Safari/537.36
Chrome Mobile 96 on Android
View result in a separate tab
Test name Executions per second
Array.prototype.concat 2095507.6 Ops/sec
spread operator 2888256.8 Ops/sec
copy on push 1387847.4 Ops/sec
directly push 1687021.2 Ops/sec
flat 0.9 Ops/sec