using System; interface IA { void f(); } class B where T : IA, new(){ public void f(int n) { DateTime st = DateTime.Now; for (int i = 0; i < n; i++){ T a = new T(); a.f(); } Console.WriteLine((DateTime.Now - st).Milliseconds + " msec"); } } struct A : IA{ public int n; public void f() { n++; } } class C{ public void f(int n){ DateTime st = DateTime.Now; for (int i = 0; i < n; i++){ IA a = new A(); a.f(); } Console.WriteLine((DateTime.Now - st).Milliseconds + " msec"); } public void fT(T a) where T : IA {a.f();} public void f2(int n){ DateTime st = DateTime.Now; for (int i = 0; i < n; i++){ fT(new A()); } Console.WriteLine((DateTime.Now - st).Milliseconds + " msec"); } } public class Test{ public static void Main(){ int n = 20000000; B b = new B(); b.f(n); C c = new C(); c.f(n); c.f2(n); } }