Demo: Benchmarking For and Foreach
We run BenchmarkDotNet on four combinations: for and foreach over an array, and for and foreach over a list of one million elements. We show that the for/foreach performance on arrays are virtually identical, while foreach on a list is nearly 5x slower than a for loop on the same list.
Previous Module
Basic Performance Optimizations
This Module
Array Performance Optimizations