fork download
  1. using System;
  2. using System.Diagnostics;
  3. using System.Threading;
  4. using System.Reflection;
  5. using System.Numerics;
  6.  
  7. public class Test
  8. {
  9. public static void runTest<T>(int count,T a, T b, Func<T,T,T> add) where T : new()
  10. {
  11. Stopwatch w = new Stopwatch();
  12. Random rnd = new Random();
  13. w.Start();
  14. for (int i = 0; i < count; i++)
  15. {
  16. a = add(a, b);
  17. }
  18. w.Stop();
  19. Console.WriteLine("{0,-25} : {1}", typeof(T).ToString(), w.Elapsed);
  20.  
  21. }
  22. public static void Main()
  23. {
  24.  
  25. Console.WriteLine("Results:");
  26. int count = (int)1e7;
  27. runTest<float>(count, 0, 28374, (a,b) => a+b);
  28. runTest<double>(count, 0, 28374, (a, b) => a + b);
  29. runTest<Complex>(count, 0, 28374, (a, b) => a + b);
  30. runTest<byte>(count, 0, 244, (a, b) => (byte)(a + b));
  31. runTest<short>(count, 0, 28374, (a, b) => (short)(a + b));
  32. runTest<int>(count, 0, 28374, (a, b) => a + b);
  33. runTest<long>(count, 0, 28374, (a, b) => a + b);
  34. runTest<decimal>(count, 0, 28374, (a, b) => a + b);
  35. runTest<BigInteger>(count, 0, 28374, (a, b) => a + b);
  36. }
  37. }
  38.  
Compilation error #stdin compilation error #stdout 0.04s 28848KB
stdin
Standard input is empty
compilation info
prog.cs(5,14): error CS0234: The type or namespace name `Numerics' does not exist in the namespace `System'. Are you missing `System.Numerics' assembly reference?
Compilation failed: 1 error(s), 0 warnings
stdout
Standard output is empty