freaktechnik/eslint-plugin-array-func

Prefer slice for copying arrays

freaktechnik opened this issue · 2 comments

Array.from etc. are probably slower. Need to investigate.

Made a little test case for peace of mind: https://jsperf.com/array-cloning-freak/1

The ranking is as follows (checked in Chromium and Firefox, so we have V8 and SpiderMonkey):

  1. Array.prototype.slice
  2. Reflect.construct(Array
  3. Array.prototype.map (performs better than Reflect.construct in SpiderMonkey)
  4. Everything else, like spreading or Array.from... (far slower)

This should actually be a rule where the user can choose their preferred method.