fork download
  1. using System;
  2.  
  3. interface IA {
  4. void f();
  5. }
  6. class B<T> where T : IA, new(){
  7. public void f(int n) {
  8. DateTime st = DateTime.Now;
  9. for (int i = 0; i < n; i++){
  10. T a = new T();
  11. a.f();
  12. }
  13. Console.WriteLine((DateTime.Now - st).Milliseconds + " msec");
  14. }
  15. }
  16.  
  17. struct A : IA{
  18. public int n;
  19. public void f() { n++; }
  20. }
  21.  
  22. class C{
  23. public void f(int n){
  24. DateTime st = DateTime.Now;
  25. for (int i = 0; i < n; i++){
  26. IA a = new A();
  27. a.f();
  28. }
  29. Console.WriteLine((DateTime.Now - st).Milliseconds + " msec");
  30. }
  31. public void fT<T>(T a) where T : IA {a.f();}
  32. public void f2(int n){
  33. DateTime st = DateTime.Now;
  34. for (int i = 0; i < n; i++){
  35. fT(new A());
  36. }
  37. Console.WriteLine((DateTime.Now - st).Milliseconds + " msec");
  38. }
  39. }
  40.  
  41. public class Test{
  42. public static void Main(){
  43. int n = 20000000;
  44. B<A> b = new B<A>();
  45. b.f(n);
  46. C c = new C();
  47. c.f(n);
  48. c.f2(n);
  49. }
  50. }
Success #stdin #stdout 1.18s 38096KB
stdin
Standard input is empty
stdout
98 msec
971 msec
75 msec