fork download
  1. using System;
  2. using System.Diagnostics;
  3.  
  4. namespace ConsoleApplication52
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. Random rnd;
  11. const int cycles = 1000000;
  12.  
  13. rnd = new Random(1);
  14.  
  15. int total1 = 0;
  16. Stopwatch sw1 = Stopwatch.StartNew();
  17.  
  18. for (int i = 0; i < cycles; i++)
  19. {
  20. if (rnd.Next() % 4 == 0)
  21. {
  22. total1++;
  23. }
  24. }
  25.  
  26. sw1.Stop();
  27.  
  28. rnd = new Random(1);
  29.  
  30. int total2 = 0;
  31. Stopwatch sw2 = Stopwatch.StartNew();
  32.  
  33. for (int i = 0; i < cycles; i++)
  34. {
  35. if ((rnd.Next() & 3) == 0)
  36. {
  37. total2++;
  38. }
  39. }
  40.  
  41. sw2.Stop();
  42.  
  43. Console.WriteLine("%: {0} in {1} ticks", total1, sw1.ElapsedTicks);
  44. Console.WriteLine("&: {0} in {1} ticks", total2, sw2.ElapsedTicks);
  45. }
  46. }
  47. }
  48.  
Success #stdin #stdout 0.1s 38080KB
stdin
Standard input is empty
stdout
%: 246462 in 440535 ticks
&: 246462 in 436757 ticks