Better HN
topnewbestaskshowjobs
Log inSign up

staeke

3 karma · joined May 23, 2019 (7y ago) · 1 submissions

Submissions

comment 7y ago · link · parent

This is nonsense. You're micro-benchmarking some detail without reflecting on how to use these methods. I take it you have this code (sort of)

  const all = [[1,2,3,4,5], [1,2,3,4,5], ...] //15000 items
  let ret = [];
  for (item of all) {
    ret = ret.concat(item);
    // Or ret.push(...item);
  }
The point of using concat is of course that you don't have to do the loop. You're shuffling bytes for no use like crazy there. Not concat's fault. You should be doing:

  [].concat(...all);
This runs in ~1ms on my machine (latest Chrome). Custom versions, and loop + push both come it at around ~4ms.