I find the lambda faster in my testing. Copy pasting MSDNs stopwatch code and decorating it with two versions of iterating a List.... ( I also changed the order of which test goes first, and I get the same timings). The Linq based iteration with a lambda goes faster.
Lambda 00:00:00.49
foreach 00:00:00.58
and the code..
var list = Enumerable.Range(0, 100000000).ToArray();
var total = 0;
var stopWatch = new Stopwatch();
stopWatch.Start();
Array.ForEach(list, x => total += x);
stopWatch.Stop();
TimeSpan ts = stopWatch.Elapsed;
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes, ts.Seconds,
ts.Milliseconds / 10);
Console.WriteLine("RunTime " + elapsedTime);
stopWatch = new Stopwatch();
stopWatch.Start();
foreach (var i in list)
{
total += i;
}
stopWatch.Stop();
// Get the elapsed time as a TimeSpan value.
ts = stopWatch.Elapsed;
// Format and display the TimeSpan value.
elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes, ts.Seconds,
ts.Milliseconds / 10);
Console.WriteLine("RunTime " + elapsedTime);