eslint-plugin-array-func icon indicating copy to clipboard operation
eslint-plugin-array-func copied to clipboard

Prefer slice for copying arrays

Open freaktechnik opened this issue 6 years ago • 2 comments

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

freaktechnik avatar Feb 15 '18 18:02 freaktechnik

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)

freaktechnik avatar Feb 18 '18 09:02 freaktechnik

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

freaktechnik avatar Feb 15 '19 23:02 freaktechnik