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. }
  32.  
  33. public class Test{
  34. public static void Main(){
  35. int n = 20000000;
  36. B<A> b = new B<A>();
  37. b.f(n);
  38. C c = new C();
  39. c.f(n);
  40. }
  41. }
Success #stdin #stdout 1.11s 37152KB
stdin
Standard input is empty
stdout
99 msec
984 msec