Skip to content

Instantly share code, notes, and snippets.

@mhkoca
Created September 25, 2019 09:38
Show Gist options
  • Save mhkoca/ab77a971744033c30efce508e12b5211 to your computer and use it in GitHub Desktop.
Save mhkoca/ab77a971744033c30efce508e12b5211 to your computer and use it in GitHub Desktop.
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