// 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 Program { private const int N = 1000000000; private static int Min1(int[] a) { return Math.Min(Math.Min(a[0], a[1]), Math.Min(a[2], a[3])); } private static int Min2(int[] x) { int a = x[0]; int b = x[1]; int c = x[2]; int d = x[3]; if (b < a) { a = b; } if (d < c) { c = d; } return (a < c) ? a : c; } public static void Main(string[] args) { int[] a = { 4, 3, 2, 1 }; DateTime dt1 = DateTime.Now; for(int i = 0; i < N; i++) { if(Min1(a) != 1) throw new Exception("Ooops"); } DateTime dt2 = DateTime.Now; Console.WriteLine("Math.Min: " + (dt2 - dt1).TotalSeconds); DateTime dt3 = DateTime.Now; for(int i = 0; i < N; i++) { if(Min2(a) != 1) throw new Exception("Ooops"); } DateTime dt4 = DateTime.Now; Console.WriteLine("Manual: " + (dt4 - dt3).TotalSeconds); } } }