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; | |
} |
It's to combat the cold start problem. JIT will not compile the methods yet, Caches will be cold, etc.
Only below code works? if I do not use warmup. I am making some web request and capture the response time of each request.
When I use with a warmup, it not execute all my request.
Stopwatch w = new Stopwatch();
w.Start();
{
a();
}
w.Stop();
Console.WriteLine($" [3] Took: {w.ElapsedMilliseconds} ms");
Don't use this to measure web requests, this function wasn't meant to do that.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
why Quick Warmup?
It's part of parallel?