Created
February 18, 2015 19:47
-
-
Save KevM/27a41aca605cf50593b9 to your computer and use it in GitHub Desktop.
Wrote this quick little performance testing harness. Guessing this is a C# right of passage kind of thing.
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
public static void MeasureMe(Action action, int count=100, int warmup = 10, int runs = 1,string messageFormat = "It took {0}ms to do this.") | |
{ | |
Enumerable.Range(0, warmup).Each(i => | |
{ | |
action(); | |
}); | |
Enumerable.Range(0, runs).Each(r => | |
{ | |
var watch = new Stopwatch(); | |
watch.Start(); | |
Enumerable.Range(0, count).Each(i => | |
{ | |
action(); | |
}); | |
watch.Stop(); | |
var output = String.Format(messageFormat, watch.ElapsedMilliseconds); | |
Console.WriteLine(output); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example usage: