You've got users complaining that it takes too long for a screen to open or for a certain piece of code to run. Wouldn't it be handy to wrap the execution of a key block of code with some timing statistics?
The following TimeIt class is derived from IDisposable which makes it easy to wrap a code block (aka
scope) with the
using keyword (this will ensure that if any exceptions are raised you'll still get to final end scope logged).
The timing internals are hidden way - it's easily accessed via a static
Log method:
using (TimeIt.Log("Calculate cost"))
{
Debug.WriteLine("Retrieving price..");
var price = pricingService.GetPrice();
var cost = notionalCalculator.GetUSDValue(price);
}