Created
June 26, 2012 20:14
-
-
Save khmylov/2998599 to your computer and use it in GitHub Desktop.
Benchmarking helper method, as seen at http://stackoverflow.com/a/1048708/656426
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 void Profile(string description, int iterations, Action func) | |
{ | |
// clean up | |
GC.Collect(); | |
GC.WaitForPendingFinalizers(); | |
GC.Collect(); | |
// warm up | |
func(); | |
var watch = Stopwatch.StartNew(); | |
for (int i = 0; i < iterations; i++) { | |
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