Skip to content

Instantly share code, notes, and snippets.

@bertwagner
Last active November 24, 2016 13:49
Show Gist options
  • Save bertwagner/0722f4f33af26b03458bf6ab54f8d26f to your computer and use it in GitHub Desktop.
Save bertwagner/0722f4f33af26b03458bf6ab54f8d26f to your computer and use it in GitHub Desktop.
Method for running other XML methods through a performance test
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