Created
March 26, 2013 09:16
-
-
Save tugberkugurlu/5244087 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Profile("i++", () => | |
{ | |
for (int i = 0; i < int.MaxValue; i++) | |
{ | |
double foo = Math.Round(Math.Sqrt(3.4F) * 7823278.9F, 2); | |
} | |
}); | |
Profile("++i", () => | |
{ | |
for (int i = 0; i < int.MaxValue; ++i) | |
{ | |
double foo = Math.Round(Math.Sqrt(3.4F) * 7823278.9F, 2); | |
} | |
}); | |
Console.ReadKey(); | |
} | |
static void Profile(string description, Action func) | |
{ | |
// clean up | |
GC.Collect(); | |
GC.WaitForPendingFinalizers(); | |
GC.Collect(); | |
// warm up | |
func(); | |
var watch = Stopwatch.StartNew(); | |
func(); | |
watch.Stop(); | |
Console.Write(description); | |
Console.WriteLine(" Time Elapsed {0} ms", watch.ElapsedMilliseconds); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment