fork download
  1. using System;
  2. using System.Linq;
  3. using System.Diagnostics;
  4.  
  5. public class Program
  6. {
  7. public static void Main()
  8. {
  9. const int Flops = 100000;
  10. const int Repeats = 100;
  11. var random = new Random();
  12. var output = Enumerable.Range(0, Flops).Select(i => random.NextDouble()).ToArray();
  13. var left = Enumerable.Range(0, Flops).Select(i => random.NextDouble()).ToArray();
  14. var right = Enumerable.Range(0, Flops).Select(i => random.NextDouble()).ToArray();
  15. var timer = Stopwatch.StartNew();
  16. for (var i = 0; i < Flops - 1; i++)
  17. {
  18. unchecked
  19. {
  20. output[i] += left[i] * right[i];
  21. }
  22. }
  23.  
  24. timer.Stop();
  25. for (var i = 0; i < Flops - 1; i++)
  26. {
  27. output[i] = random.NextDouble();
  28. }
  29.  
  30. timer = Stopwatch.StartNew();
  31. for (var j = 0; j < Repeats; j++)
  32. {
  33. for (var i = 0; i < Flops - 1; i++)
  34. {
  35. unchecked
  36. {
  37. output[i] += left[i] * right[i];
  38. }
  39. }
  40. }
  41.  
  42. timer.Stop();
  43. Console.WriteLine("ms: {0}", timer.ElapsedMilliseconds);
  44. Console.WriteLine("MFLOPS: {0}", ((double)Flops * Repeats) / timer.ElapsedMilliseconds / 1000.0);
  45. }
  46. }
Success #stdin #stdout 0.25s 24344KB
stdin
Standard input is empty
stdout
ms: 153
MFLOPS: 65.359477124183