C#C
C#2y ago
Tony Wang

C# IEnumerable ToArray() Benchmark

I was benchmarking different kinds of IEnumerable Methods out of curiosity and found something very strange: Calling ToArray() on a temporary array is relatively slow.

I am aware, that array.ToArray() creates a copy of array, but I would have thought that the compiler was smart enough to ommit the copy if array is an temporary object. Am I missing something?
Screenshot_2024-04-19_162540.png
Screenshot_2024-04-19_162557.png
Was this page helpful?