Advertisement
Guest User

Untitled

a guest
Oct 13th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. static Dictionary<ReportType, Action> dictReports = new Dictionary<ReportType, Action>();
  2. static void Main(string[] args)
  3. {
  4. Reporter reporter = new Reporter();
  5. dictReports.Add(ReportType.Daily, new Action(reporter.GetDailyReport));
  6. dictReports.Add(ReportType.Weekly, new Action(reporter.GetWeeklyReport));
  7. dictReports.Add(ReportType.Monthly, new Action(reporter.GetMonthlyReport));
  8. dictReports.Add(ReportType.Annual, new Action(reporter.GetAnnualReport));
  9.  
  10. Stopwatch stopwatch = new Stopwatch();
  11. stopwatch.Start();
  12.  
  13. for (long i = 0; i < 100000000; i++)
  14. {
  15. dictReports[ReportType.Weekly]();
  16. }
  17.  
  18. stopwatch.Stop();
  19. Console.WriteLine($"Time elapsed (dictionary): {stopwatch.Elapsed}");
  20.  
  21. stopwatch = new Stopwatch();
  22. stopwatch.Start();
  23.  
  24. for (long i = 0; i < 100000000; i++)
  25. {
  26. PrepareReport(ReportType.Weekly);
  27. }
  28.  
  29. stopwatch.Stop();
  30. Console.WriteLine($"Time elapsed (if): {stopwatch.Elapsed}");
  31. Console.ReadLine();
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement