Function performance: List and Vector benchtest

For one thing, a lot of stuff other than prepending and appending is going on in that code.

Another thing is that the table doesn’t really list the time cost. It shows how the time it takes to complete an operation evolves as a collection gets bigger. Constant means that if operation X takes 10 milliseconds on a collection of size 10, then it will take 10 milliseconds on a collection of size 1 million. Linear means that if that operation takes 10 milliseconds for size 10, and 100 for size 100, it will probably take around 1 million milliseconds for size 1 million. eC means that the time will grow a little but very slowly compared to L. But that doesn’t say anything about how long an operation really takes. Append on List can be L but still very fast on relatively small lists. While maybe on Vector it’s pretty slow compared to List for a small size, but will be faster than List for larger sizes.

And not entirely related to the question, but I wouldn’t use LazyList as an intermediate builder for another collection. In this case you could use List.iterate(List(1), numRows)(...). Or in general if you want to avoid generating intermediary garbage or want to fuse intermediary operations together, I would start from Iterator instead of LazyList.

1 Like