Is there a significant/performance difference between List and Array?

Trying to create a draw-line mechanic in my game and I am using a Vector2 Array to store the points, although I have seen people online using Lists and then converting them to arrays by using list.toArray() to convert the line points to edge collider points. Why is that?

Very low difference, it depends on your hash calculation functions and comparison.

In this case, the Array is faster, but you should use List because you need to Add items.

Also, this performance difference is not sensible.

Thanks.

Arrays are faster, but in smaller sizes it doesn’t really make much difference. When you get to larger sizes ( > 1000 ) and poll them rapidly it starts to make a difference if it’s an array or list.

List also provides a lot of features that Array doesn’t, so that’s definitely something to consider.

Always use lists until you can prove arrays provide a substantial benefit IMO. Nothing I hate more then having to deal with less then elegant code because some blockhead uses arrays everywhere for no good reason.

5 Likes