// 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; using System.Dynamic; namespace E { public class FooBar { public int Count { get; set; } public FooBar() { Count = 0; } public void DoNothing() { Count++; } } public class Program { private const int N = 100000000; public static void TestStaticBinding(FooBar fb) { DateTime dt1 = DateTime.Now; for(int i = 0; i < N; i++) { fb.DoNothing(); } if(fb.Count != N) throw new Exception("Ooops"); DateTime dt2 = DateTime.Now; Console.WriteLine("Static : {0:F3}", (dt2 - dt1).TotalSeconds); } public static void TestDynamicBinding(dynamic fb) { DateTime dt1 = DateTime.Now; for(int i = 0; i < N; i++) { fb.DoNothing(); } if(fb.Count != N) throw new Exception("Ooops"); DateTime dt2 = DateTime.Now; Console.WriteLine("Dynamic : {0:F3}", (dt2 - dt1).TotalSeconds); } public static void Main(string[] args) { TestStaticBinding(new FooBar()); TestDynamicBinding(new FooBar()); TestStaticBinding(new FooBar()); TestDynamicBinding(new FooBar()); TestStaticBinding(new FooBar()); TestDynamicBinding(new FooBar()); } } }