Slice vs Arrays

Performance

  • Slice operations are cheap!
  • Slicing: Creates a new slice header.
  • Assigning a Slice to another Slice or, passing it to a function: Only copies the slice header.
  • Slice header has a fixed size and it doesn't change even if we have got millions of elements.
  • Array can be expensive as compared to Slice.
  • Assigning an array to another array or passing it to a function: Copies all the elements of it.

See also