fork download
  1. using System;
  2. using System.Diagnostics;
  3.  
  4. struct Test
  5. {
  6. int i;
  7. public Test(int i)
  8. {
  9. this.i = i;
  10. }
  11. public void Init(int i)
  12. {
  13. this.i = i;
  14. }
  15. }
  16.  
  17. class Program
  18. {
  19. static void Main(string[] args)
  20. {
  21. const int length = 0x1000000;
  22. var tests = new Test[length];
  23.  
  24. for (var i = 0; i < length; i++)
  25. tests[i] = new Test(i);
  26. for (var i = 0; i < length; i++)
  27. tests[i].Init(i);
  28. for (var i = 0; i < length; i++)
  29. tests[i] = new Test(i);
  30. for (var i = 0; i < length; i++)
  31. tests[i].Init(i);
  32.  
  33. var s = new Stopwatch();
  34. s.Start();
  35. for (var j = 0; j < 3; j++)
  36. for (var i = 0; i < length; i++)
  37. tests[i] = new Test(i);
  38. s.Stop();
  39. Console.WriteLine(".ctor(): {0}ms", s.ElapsedMilliseconds);
  40. s.Start();
  41. for (var j = 0; j < 3; j++)
  42. for (var i = 0; i < length; i++)
  43. tests[i].Init(i);
  44. s.Stop();
  45. Console.WriteLine("Init(): {0}ms", s.ElapsedMilliseconds);
  46. }
  47. }
  48.  
Success #stdin #stdout 0.7s 99584KB
stdin
Standard input is empty
stdout
.ctor(): 116ms
Init(): 210ms