using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; public class Program { public static void Main(string[] args) { var sw = new Stopwatch(); var array = new double[10000000]; for (int i = 0; i < array.Length; i++) { array[i] = Math.Exp(12); } double tmp; { sw.Reset(); sw.Start(); for (int i = 0; i < array.Length; i++) { tmp = Math.Tanh(Math.Log(array[i]) / 7); } sw.Stop(); Console.WriteLine("Loop using for: {0}ms", sw.Elapsed.TotalMilliseconds); } { sw.Reset(); sw.Start(); foreach(double d in array){ tmp = Math.Tanh(Math.Log(d) / 7); } sw.Stop(); Console.WriteLine("Loop using foreach: {0}ms", sw.Elapsed.TotalMilliseconds); } } }