Created
August 25, 2020 10:34
-
-
Save badamczewski/f7e3114411f1fa0e7c1d190405d70ecb to your computer and use it in GitHub Desktop.
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 long Measure(Action a) | |
{ | |
// | |
// Quick Wormup. | |
// | |
Console.WriteLine(" [1] Warm Up ... "); | |
for (int i = 0; i < 10; i++) | |
{ | |
a(); | |
} | |
double avg = 0; | |
Console.WriteLine(" [2] Running ... "); | |
for (int i = 0; i < 10; i++) | |
{ | |
Stopwatch w = new Stopwatch(); | |
w.Start(); | |
{ | |
a(); | |
} | |
w.Stop(); | |
avg += w.ElapsedMilliseconds; | |
Console.WriteLine($" [3] Took: {w.ElapsedMilliseconds} ms"); | |
} | |
Console.WriteLine($" [4] AVG: {avg / 10} ms"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@cpatel22
Don't use this to measure web requests, this function wasn't meant to do that.