How well do you know your code is running in the wild? How long do operations take, on average?
Using System.Diagnostics.Stopwatch to capture the duration of an operation works once, but what about repeated instances of that operation? Would you like to know how many times the operation occurred, how much time was spent on that operation, the average time spent per iteration, and how long the longest operation took?
Chonograph aims to solve this with a simple wrapper around Stopwatch which keeps track of your performance statistics.
Your code will look like this:
var chrono = Factory.GetChronograph("operation name");
chrono.Start();
// the operation you want to measure
TimeSpan latest = chrono.Stop()
Console.WriteLine($"Latest: {latest}");
Console.WriteLine($"Mean: {chrono.ActiveSession.Mean}");
or
TimeSpan latest = chrono.MeasureAction(() =>
{
// some code you want to measure
});
Console.WriteLine($"Latest: {latest}");
Console.WriteLine($"Mean: {chrono.ActiveSession.Mean}");
or
chrono.MeasureAction(someMethodToCall);
Check out the SampleApp project to see more usage examples. Invalid operations will throw exceptions, including starting the chrono when it already running, and stopping the chrono when it wasn't running.