fork(2) download
  1. using System;
  2. using System.Diagnostics;
  3.  
  4. namespace RiderTestApp
  5. {
  6. internal class Program
  7. {
  8. public static double Round(double d)
  9. {
  10. return Math.Round(d);
  11. }
  12.  
  13. public static double RoundWithPrecision(double d)
  14. {
  15. return Math.Round(d, 0);
  16. }
  17.  
  18. public static double Floor(double d)
  19. {
  20. return Math.Floor(d + 0.5);
  21. }
  22.  
  23. private static void TestRound(int n)
  24. {
  25. var s = new Stopwatch();
  26.  
  27. double d = 0;
  28.  
  29. s.Start();
  30.  
  31. for (var i = 0; i < n; i++)
  32. {
  33. d += Round(3.5);
  34. }
  35.  
  36. s.Stop();
  37.  
  38. Console.WriteLine("Round - d: " + d + ", Time: " + s.ElapsedMilliseconds);
  39. }
  40.  
  41. private static void TestRoundWithPrecision(int n)
  42. {
  43. var s = new Stopwatch();
  44.  
  45. double d = 0;
  46.  
  47. s.Start();
  48.  
  49. for (var i = 0; i < n; i++)
  50. {
  51. d += RoundWithPrecision(3.5);
  52. }
  53.  
  54. s.Stop();
  55.  
  56. Console.WriteLine("RoundWithPrecision - d: " + d + ", Time: " + s.ElapsedMilliseconds);
  57. }
  58.  
  59. private static void TestFloor(int n)
  60. {
  61. var s = new Stopwatch();
  62.  
  63. double d = 0;
  64.  
  65. s.Start();
  66.  
  67. for (var i = 0; i < n; i++)
  68. {
  69. d += Floor(3.5);
  70. }
  71.  
  72. s.Stop();
  73.  
  74. Console.WriteLine("Floor - d: " + d + ", Time: " + s.ElapsedMilliseconds);
  75. }
  76.  
  77. public static void Main()
  78. {
  79. Console.WriteLine(Environment.OSVersion);
  80. Console.WriteLine(Type.GetType("Mono.Runtime") == null ? "MS" : "Mono");
  81. Console.WriteLine(Environment.Version);
  82.  
  83. #if DEBUG
  84. Console.WriteLine("Mode=Debug");
  85. #else
  86. Console.WriteLine("Mode=Release");
  87. #endif
  88.  
  89. Console.WriteLine();
  90.  
  91. const int n1 = 1000000;
  92.  
  93. TestRound(n1);
  94. TestRoundWithPrecision(n1);
  95. TestFloor(n1);
  96.  
  97. Console.WriteLine();
  98.  
  99. const int n2 = n1 * 10;
  100.  
  101. TestRound(n2);
  102. TestRoundWithPrecision(n2);
  103. TestFloor(n2);
  104.  
  105. Console.WriteLine();
  106.  
  107. const int n3 = n2 * 10;
  108.  
  109. TestRound(n3);
  110. TestRoundWithPrecision(n3);
  111. TestFloor(n3);
  112. }
  113. }
  114. }
  115.  
Success #stdin #stdout 1.85s 29808KB
stdin
Standard input is empty
stdout
Unix 3.16.0.4
Mono
4.0.30319.17020
Mode=Release

Round - d: 4000000, Time: 3
RoundWithPrecision - d: 4000000, Time: 5
Floor - d: 4000000, Time: 7

Round - d: 40000000, Time: 34
RoundWithPrecision - d: 40000000, Time: 56
Floor - d: 40000000, Time: 75

Round - d: 400000000, Time: 350
RoundWithPrecision - d: 400000000, Time: 567
Floor - d: 400000000, Time: 740