Guest User

Untitled

a guest
Jul 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. void Main()
  2. {
  3. RunDirectly();
  4. RunIndirectly();
  5. var runs = 1000000;
  6.  
  7. var sw = new Stopwatch();
  8.  
  9. sw.Start();
  10. for (int i = 0; i < runs; i++)
  11. {
  12. RunDirectly();
  13. }
  14. sw.Stop();
  15. Console.ForegroundColor = ConsoleColor.Green;
  16. Console.WriteLine($"{runs} Direct Executions: {sw.ElapsedMilliseconds}");
  17.  
  18. sw.Reset();
  19.  
  20. sw.Start();
  21. for (int i = 0; i < runs; i++)
  22. {
  23. RunIndirectly();
  24. }
  25. sw.Stop();
  26. Console.ForegroundColor = ConsoleColor.Blue;
  27. Console.WriteLine($"{runs} Indirect Executions: {sw.ElapsedMilliseconds}");
  28.  
  29. sw.Reset();
  30.  
  31. sw.Start();
  32. for (int i = 0; i < runs; i++)
  33. {
  34. RunIndirectly();
  35. }
  36. sw.Stop();
  37. Console.ForegroundColor = ConsoleColor.Blue;
  38. Console.WriteLine($"{runs} Indirect Executions: {sw.ElapsedMilliseconds}");
  39.  
  40. sw.Reset();
  41.  
  42. sw.Start();
  43. for (int i = 0; i < runs; i++)
  44. {
  45. RunDirectly();
  46. }
  47. sw.Stop();
  48. Console.ForegroundColor = ConsoleColor.Green;
  49. Console.WriteLine($"{runs} Direct Executions: {sw.ElapsedMilliseconds}");
  50.  
  51. sw.Reset();
  52.  
  53. sw.Start();
  54. for (int i = 0; i < runs; i++)
  55. {
  56. RunDirectly();
  57. }
  58. sw.Stop();
  59. Console.ForegroundColor = ConsoleColor.Green;
  60. Console.WriteLine($"{runs} Direct Executions: {sw.ElapsedMilliseconds}");
  61.  
  62. sw.Reset();
  63.  
  64. sw.Start();
  65. for (int i = 0; i < runs; i++)
  66. {
  67. RunIndirectly();
  68. }
  69. sw.Stop();
  70. Console.ForegroundColor = ConsoleColor.Blue;
  71. Console.WriteLine($"{runs} Indirect Executions: {sw.ElapsedMilliseconds}");
  72.  
  73. sw.Reset();
  74.  
  75. sw.Start();
  76. for (int i = 0; i < runs; i++)
  77. {
  78. RunIndirectly();
  79. }
  80. sw.Stop();
  81. Console.ForegroundColor = ConsoleColor.Blue;
  82. Console.WriteLine($"{runs} Indirect Executions: {sw.ElapsedMilliseconds}");
  83.  
  84. sw.Reset();
  85.  
  86. sw.Start();
  87. for (int i = 0; i < runs; i++)
  88. {
  89. RunDirectly();
  90. }
  91. sw.Stop();
  92. Console.ForegroundColor = ConsoleColor.Green;
  93. Console.WriteLine($"{runs} Direct Executions: {sw.ElapsedMilliseconds}");
  94.  
  95. sw.Reset();
  96.  
  97. }
  98.  
  99. int count = 0;
  100.  
  101. private void RunDirectly()
  102. {
  103. count++;
  104. }
  105.  
  106. private void RunIndirectly()
  107. {
  108. Action m = () => { count++; };
  109. m();
  110. }
Add Comment
Please, Sign In to add comment