fork download
  1. using System;
  2. using System.Diagnostics;
  3.  
  4. public class Test
  5. {
  6. static Random random = new Random();
  7.  
  8. public static Double Random() {
  9. return random.NextDouble();
  10. }
  11.  
  12. public static Double Random2() {
  13. return -1;
  14. }
  15.  
  16. public static void Main()
  17. {
  18. {
  19. Stopwatch s = new Stopwatch();
  20. Double a = 0;
  21. s.Start();
  22. for (Int32 i = 0; i < 5000000; i++)
  23. a += Random();
  24. s.Stop();
  25. Console.WriteLine(s.ElapsedMilliseconds);
  26. }
  27.  
  28. {
  29. Stopwatch s = new Stopwatch();
  30. Double a = 0;
  31. s.Start();
  32. for (Int32 i = 0; i < 5000000; i++)
  33. a += Random2();
  34. s.Stop();
  35. Console.WriteLine(s.ElapsedMilliseconds);
  36. }
  37.  
  38. {
  39. Stopwatch s = new Stopwatch();
  40. Double a = 0;
  41. s.Start();
  42. for (Int32 i = 0; i < 5000000; i++)
  43. a += random.NextDouble();
  44. s.Stop();
  45. Console.WriteLine(s.ElapsedMilliseconds);
  46. }
  47. }
  48. }
Success #stdin #stdout 0.43s 37024KB
stdin
Standard input is empty
stdout
174
58
167