Clarification: I incorrectly used repeatElement() to create an Array here while it returns an instance of 'Repeated' not Array, and the difference is big.
However, the same performance issue can be seen with Arrays too, and even worse (~10x).
However, the same performance issue can be seen with Arrays too, and even worse (~10x).
But why accessing the last element in Repeated using the subscript is faster? It's because the subscript function is optimized to simply return the repeated value. Whereas 'last' property is implemented in a generic way in BidirectionalCollection, and it's slower for some reason.