Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static Dictionary<ReportType, Action> dictReports = new Dictionary<ReportType, Action>();
- static void Main(string[] args)
- {
- Reporter reporter = new Reporter();
- dictReports.Add(ReportType.Daily, new Action(reporter.GetDailyReport));
- dictReports.Add(ReportType.Weekly, new Action(reporter.GetWeeklyReport));
- dictReports.Add(ReportType.Monthly, new Action(reporter.GetMonthlyReport));
- dictReports.Add(ReportType.Annual, new Action(reporter.GetAnnualReport));
- Stopwatch stopwatch = new Stopwatch();
- stopwatch.Start();
- for (long i = 0; i < 100000000; i++)
- {
- dictReports[ReportType.Weekly]();
- }
- stopwatch.Stop();
- Console.WriteLine($"Time elapsed (dictionary): {stopwatch.Elapsed}");
- stopwatch = new Stopwatch();
- stopwatch.Start();
- for (long i = 0; i < 100000000; i++)
- {
- PrepareReport(ReportType.Weekly);
- }
- stopwatch.Stop();
- Console.WriteLine($"Time elapsed (if): {stopwatch.Elapsed}");
- Console.ReadLine();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement