Last active
November 24, 2016 13:49
-
-
Save bertwagner/0722f4f33af26b03458bf6ab54f8d26f to your computer and use it in GitHub Desktop.
Method for running other XML methods through a performance test
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
public static double RunPerformanceTest(string filePath, Action<string> performanceTestMethod) | |
{ | |
Stopwatch sw = new Stopwatch(); | |
int iterations = 50; | |
double elapsedMilliseconds = 0; | |
// Run the method 50 times to rule out any bias. | |
for (var i = 0; i < iterations; i++) | |
{ | |
sw.Restart(); | |
performanceTestMethod(filePath); | |
sw.Stop(); | |
elapsedMilliseconds += sw.ElapsedMilliseconds; | |
} | |
// Calculate the average elapsed seconds per run | |
double avergeSeconds = (elapsedMilliseconds / iterations) / 1000.0; | |
return avergeSeconds; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment