fork download
  1. using System;
  2. using System.Diagnostics;
  3.  
  4. namespace PruebaRendimientoAbstractInterface
  5. {
  6. interface IInterfaceExample
  7. {
  8. void Y();
  9. }
  10.  
  11. class ImplementsInterface : IInterfaceExample
  12. {
  13. public void Y()
  14. {
  15. }
  16. }
  17.  
  18. class BaseExample
  19. {
  20. public virtual void Y()
  21. {
  22. }
  23. }
  24.  
  25. class DerivesBase : BaseExample
  26. {
  27. public override void Y()
  28. {
  29. }
  30. }
  31.  
  32. class Program
  33. {
  34. const int _max = 100000000;
  35. static void Main()
  36. {
  37. IInterfaceExample interface1 = new ImplementsInterface();
  38. BaseExample base1 = new DerivesBase();
  39. interface1.Y();
  40. base1.Y();
  41.  
  42. var s1 = Stopwatch.StartNew();
  43. for (int i = 0; i < _max; i++)
  44. {
  45. interface1.Y();
  46. }
  47. s1.Stop();
  48. var s2 = Stopwatch.StartNew();
  49. for (int i = 0; i < _max; i++)
  50. {
  51. base1.Y();
  52. }
  53. s2.Stop();
  54. Console.WriteLine(((double)(s1.Elapsed.TotalMilliseconds * 1000 * 1000) /
  55. _max).ToString("0.00 ns"));
  56. Console.WriteLine(((double)(s2.Elapsed.TotalMilliseconds * 1000 * 1000) /
  57. _max).ToString("0.00 ns"));
  58. Console.Read();
  59. }
  60. }
  61. }
Success #stdin #stdout 1.02s 33912KB
stdin
Standard input is empty
stdout
6.38 ns
3.41 ns