Created
September 25, 2019 09:38
-
-
Save mhkoca/ab77a971744033c30efce508e12b5211 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment