Basically, switch foreach loop to for
This does not always make perf better, and in fact can make iteration worse on some collection types. When used over an array, there is no difference.
On Unity (the old runtime) the foreach loop used to be slower because of the old runtime, which still tried to box the access by using IEnumerator...
With the new runtime it should behave way better and optimized
This does not always make perf better, and in fact can make iteration worse on some collection types. When used over an array, there is no difference.
Thanks for the insightful feedback BenchmarkDotNet is a liar 馃槀
When in doubt, you can look at the IL between a foreach and a for loop. I think for an array the compiled IL is identical.
Another layer (and ultimately the one that matters) that you can check is release build disassembly.
Most helpful comment
When in doubt, you can look at the IL between a foreach and a for loop. I think for an array the compiled IL is identical.
Another layer (and ultimately the one that matters) that you can check is release build disassembly.