fork(1) download
  1. using System;
  2. using System.Diagnostics;
  3.  
  4. struct Struct
  5. {
  6. public float X;
  7. public float Y;
  8.  
  9. public Struct(float x, float y)
  10. {
  11. X = x; Y = y;
  12. }
  13. }
  14.  
  15. class Hoge
  16. {
  17. const int Count = 1000 * 10000;
  18.  
  19. public static void Main()
  20. {
  21. Struct s = default(Struct);
  22.  
  23. Stopwatch sw = new Stopwatch();
  24. sw.Start();
  25.  
  26. float total = 0;
  27.  
  28. for (int i = 0; i < Count; ++i)
  29. {
  30. s = new Struct(i, i * 2);
  31. total += s.X;
  32. total += s.Y;
  33. }
  34.  
  35. sw.Stop();
  36. Console.WriteLine("" + total + " " + s.Y + " " + sw.ElapsedMilliseconds);
  37.  
  38. sw.Reset();
  39. sw.Start();
  40.  
  41. total = 0;
  42.  
  43. for (int i = 0; i < Count; ++i)
  44. {
  45. s.X = i;
  46. s.Y = i * 2;
  47.  
  48. total += s.X;
  49. total += s.Y;
  50. }
  51.  
  52. sw.Stop();
  53. Console.WriteLine("" + total + " " + s.Y + " " + sw.ElapsedMilliseconds);
  54. }
  55. }
Success #stdin #stdout 0.3s 33904KB
stdin
Standard input is empty
stdout
1.512465E+14 2E+07  147
1.512465E+14 2E+07  126