Last active
February 16, 2016 02:53
-
-
Save gyuwon/59ba8eb3763f559efb38 to your computer and use it in GitHub Desktop.
Compilier optimization
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
using System; | |
using System.Diagnostics; | |
namespace Optimization | |
{ | |
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
var instance = new Program(); | |
int loop = 1000 * 1000 * 1000; | |
instance.Idle(loop); | |
instance.Direct(loop); | |
instance.Delegate(loop); | |
} | |
public void TargetMethod() | |
{ | |
} | |
private void Idle(int loop) | |
{ | |
Stopwatch stopwatch = Stopwatch.StartNew(); | |
for (int i = 0; i < loop; i++) | |
{ | |
} | |
stopwatch.Stop(); | |
Console.WriteLine(stopwatch.Elapsed); | |
} | |
private void Direct(int loop) | |
{ | |
Stopwatch stopwatch = Stopwatch.StartNew(); | |
for (int i = 0; i < loop; i++) | |
{ | |
TargetMethod(); | |
} | |
stopwatch.Stop(); | |
Console.WriteLine(stopwatch.Elapsed); | |
} | |
private void Delegate(int loop) | |
{ | |
Action del = TargetMethod; | |
Stopwatch stopwatch = Stopwatch.StartNew(); | |
for (int i = 0; i < loop; i++) | |
{ | |
del(); | |
} | |
stopwatch.Stop(); | |
Console.WriteLine(stopwatch.Elapsed); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment