// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; namespace E { public class MainClass { private const int N = 1000000; private const int REP = 1000; public static void Main(string[] args) { int[] a = new int[N]; DateTime t1 = DateTime.Now; for(int j = 0; j < REP; j++) { for(int i = 0; i < a.Length; i++) { if(a[i] != 0) throw new Exception("This will never happen"); } } DateTime t2 = DateTime.Now; Console.WriteLine("Inside: " + (t2 - t1).TotalSeconds); DateTime t3 = DateTime.Now; for(int j = 0; j < REP; j++) { int len = a.Length; for(int i = 0; i < len; i++) { if(a[i] != 0) throw new Exception("This will never happen"); } } DateTime t4 = DateTime.Now; Console.WriteLine("Outside: " + (t4 - t3).TotalSeconds); } } }