This is lesson 10 of 12 in this module Course 96% complete

Demo: Benchmarking For and Foreach

Premium Content

Sign in with your account or join us to access this lesson.

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.