I find these useful
http://accelero.codeplex.com/SourceControl/changeset/view/22633#290971
http://accelero.codeplex.com/SourceControl/changeset/view/22633#290973
http://accelero.codeplex.com/SourceControl/changeset/view/22633#290972
TickTimer is a cut down copy of Stopwatch that starts when constructed and does not support restarting. It will also notify you if the current hardware does not support high resolution timing (Stopwatch swallows this problem)
So this
var tickTimer = new TickTimer();
//call a method that takes some time
DoStuff();
tickTimer.Stop();
Debug.WriteLine("Elapsed HighResElapsedTicks " + tickTimer.HighResElapsedTicks);
Debug.WriteLine("Elapsed DateTimeElapsedTicks " + tickTimer.DateTimeElapsedTicks);
Debug.WriteLine("Elapsed ElapsedMilliseconds " + tickTimer.ElapsedMilliseconds);
Debug.WriteLine("Start Time " + new DateTime(tickTimer.DateTimeUtcStartTicks).ToLocalTime().ToLongTimeString());
will output this
Elapsed HighResElapsedTicks 10022886
Elapsed DateTimeElapsedTicks 41896
Elapsed ElapsedMilliseconds 4.18966178849554
Start Time 11:44:58
DebugTimer is a wrapper for TickTimer that will write the result to Debug. (note: it supports the Disposable pattern)
So this
using (new DebugTimer("DoStuff"))
{
//call a method that takes some time
DoStuff();
}
will output this to the debug window
DoStuff: Total 3.6299 ms
IterationDebugTimer is for timing how long it takes to run an operation multiple times and write the result to Debug. It will also perform an initial run that is not included so as to ignore startup time. (note: it supports the Disposable pattern)
So this
int x;
using (var iterationDebugTimer = new IterationDebugTimer("Add", 100000))
{
iterationDebugTimer.Run(() =>
{
x = 1+4;
});
}
Will output this
Add: Iterations 100000
Total 1.198540 ms
Single 0.000012 ms