Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36
Chrome 66
Mac OS X 10.12.6
Other
6 years ago
Test name Executions per second
Spread Push 979419.3 Ops/sec
Concat Reassign 997431.3 Ops/sec
Apply Push 3093752.0 Ops/sec
Script Preparation code:
AخA
 
var data = [
  1, 2, 3, 4,
  [1, 2, 3, 4],
  5, 6, 7, 8,
  [1, 2, 3, 4]
];
Tests:
  • Spread Push

     
    (function fn(items){
      var result = [];
      items.forEach(item => {
        if(item.pop) {
          result.push(...fn(item));
        } else {
          result.push(item);
        }
      });
      return result;
    })(data);
  • Concat Reassign

     
    (function fn(items){
      var result = [];
      items.forEach(item => {
        if(item.pop) {
          result = result.concat(fn(item));
        } else {
          result.push(item);
        }
      });
      return result;
    })(data);
  • Apply Push

     
    (function fn(items){
      var result = [];
      items.forEach(item => {
        if(item.pop) {
          result.push.apply(result, fn(item));
        } else {
          result.push(item);
        }
      });
      return result;
    })(data);