I'm writing some performance tests, and want to be able to time a method that is asynchronous. The code looks like this, where action
is a Func<Task<HttpResponseMessage>>
:
var sw = new Stopwatch();
HttpResponseMessage response = null;
sw.Start();
response = await action().ConfigureAwait(continueOnCapturedContext: false);
sw.Stop();
The code compiles and runs ok, but the measured milliseconds are about 100 times higher than the request timings we see in Fiddler - Fiddler reports 200-300ms, but the stop watch reports ~30,000ms. Is there some catch about timing asynchronous methods? Is the solution to do the timing in the action itself (which would be annoying?)