fork download
  1. using System;
  2. using System.Diagnostics;
  3.  
  4. class Program
  5. {
  6. static void Foo(Action action)
  7. {
  8. var s = Stopwatch.StartNew();
  9. for (int i = 0; i < _max; i++) { action(); }
  10. s.Stop();
  11. Console.WriteLine(((double)(s.Elapsed.TotalMilliseconds * 1000 * 1000) / _max).ToString("0.00 ns"));
  12. }
  13.  
  14. const int _max = 100000000;
  15. static void Main()
  16. {
  17. Foo(Method1);
  18. Foo(Method2);
  19.  
  20. // for cache effects
  21. Foo(Method2);
  22. Foo(Method1);
  23. }
  24.  
  25. static void Method1()
  26. {
  27. Method3(flag: true, size: 1, name: "Perl");
  28. }
  29.  
  30. static void Method2()
  31. {
  32. Method3(1, "Perl", true);
  33. }
  34.  
  35. static void Method3(int size, string name, bool flag)
  36. {
  37. if (!flag && size != -1 && name != null)
  38. {
  39. throw new Exception();
  40. }
  41. }
  42. }
Success #stdin #stdout 3.9s 33992KB
stdin
Standard input is empty
stdout
9.65 ns
9.65 ns
9.64 ns
9.67 ns