Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Main()
- {
- RunDirectly();
- RunIndirectly();
- var runs = 1000000;
- var sw = new Stopwatch();
- sw.Start();
- for (int i = 0; i < runs; i++)
- {
- RunDirectly();
- }
- sw.Stop();
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine($"{runs} Direct Executions: {sw.ElapsedMilliseconds}");
- sw.Reset();
- sw.Start();
- for (int i = 0; i < runs; i++)
- {
- RunIndirectly();
- }
- sw.Stop();
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.WriteLine($"{runs} Indirect Executions: {sw.ElapsedMilliseconds}");
- sw.Reset();
- sw.Start();
- for (int i = 0; i < runs; i++)
- {
- RunIndirectly();
- }
- sw.Stop();
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.WriteLine($"{runs} Indirect Executions: {sw.ElapsedMilliseconds}");
- sw.Reset();
- sw.Start();
- for (int i = 0; i < runs; i++)
- {
- RunDirectly();
- }
- sw.Stop();
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine($"{runs} Direct Executions: {sw.ElapsedMilliseconds}");
- sw.Reset();
- sw.Start();
- for (int i = 0; i < runs; i++)
- {
- RunDirectly();
- }
- sw.Stop();
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine($"{runs} Direct Executions: {sw.ElapsedMilliseconds}");
- sw.Reset();
- sw.Start();
- for (int i = 0; i < runs; i++)
- {
- RunIndirectly();
- }
- sw.Stop();
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.WriteLine($"{runs} Indirect Executions: {sw.ElapsedMilliseconds}");
- sw.Reset();
- sw.Start();
- for (int i = 0; i < runs; i++)
- {
- RunIndirectly();
- }
- sw.Stop();
- Console.ForegroundColor = ConsoleColor.Blue;
- Console.WriteLine($"{runs} Indirect Executions: {sw.ElapsedMilliseconds}");
- sw.Reset();
- sw.Start();
- for (int i = 0; i < runs; i++)
- {
- RunDirectly();
- }
- sw.Stop();
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine($"{runs} Direct Executions: {sw.ElapsedMilliseconds}");
- sw.Reset();
- }
- int count = 0;
- private void RunDirectly()
- {
- count++;
- }
- private void RunIndirectly()
- {
- Action m = () => { count++; };
- m();
- }
Add Comment
Please, Sign In to add comment