Skip to content


The Clock class offers a simple yet powerful way to measure and log the duration of operations within your applications. It supports both named and default timers, allowing for flexible performance tracking.


  • Start and Stop Timers: Easily start and stop timers to measure the duration of code execution.
  • Named Timers: Utilize named timers for tracking multiple operations simultaneously.
  • Default Timer: Use a default timer for quick and straightforward measurements.
  • Logging: Option to automatically log the duration of operations upon stopping a timer so that you don't have to do it yourself.

Usage Example

Below are some examples of how you can use the Clock class.

Starting and Stopping a Default Timer

await Task.Delay(1000);
// Console: Process took 00:00:01.0119411

Using Named Timers

TimeSpan duration = Clock.Stop("databaseQuery", log: false); // Does not log the duration
Log.Info($"Database query took {duration.TotalMilliseconds} ms.");

This utility class is designed to provide insights into your application's performance, making it a handy tool for development and debugging.