Skip to content

Instantly share code, notes, and snippets.

@khmylov
Created June 26, 2012 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khmylov/2998599 to your computer and use it in GitHub Desktop.
Save khmylov/2998599 to your computer and use it in GitHub Desktop.
Benchmarking helper method, as seen at http://stackoverflow.com/a/1048708/656426
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