DebugTimer 0.6.0

dotnet add package DebugTimer --version 0.6.0
                    
NuGet\Install-Package DebugTimer -Version 0.6.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DebugTimer" Version="0.6.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DebugTimer" Version="0.6.0" />
                    
Directory.Packages.props
<PackageReference Include="DebugTimer" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DebugTimer --version 0.6.0
                    
#r "nuget: DebugTimer, 0.6.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DebugTimer@0.6.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DebugTimer&version=0.6.0
                    
Install as a Cake Addin
#tool nuget:?package=DebugTimer&version=0.6.0
                    
Install as a Cake Tool

DebugTimer is a lightweight source-only library for measuring elapsed time in development diagnostics.

It has zero impact when disabled, all timing calls are marked with [Conditional("DEBUG_TIMER")], so they are omitted by the compiler unless the symbol is defined.

Features

  • Source-only package (no runtime assembly)
  • Simple Start / Stop API
  • Supports integer and string tags
  • Global key API for custom scenarios
  • Optional custom logger callback
  • Fallback logging with Debug.Print

Installation

dotnet add package DebugTimer

Enabling timing

Timing methods execute only when DEBUG_TIMER is defined.

This package includes a build/DebugTimer.props file that adds DEBUG_TIMER for Debug configuration:

<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
  <DefineConstants>$(DefineConstants);DEBUG_TIMER</DefineConstants>
</PropertyGroup>

If needed, you can define DEBUG_TIMER manually in your project.

Usage

Basic usage

using Pozitron.Diagnostics;

public sealed class UserService
{
    public void GetUsers()
    {
        DebugTimer.Start();

        // code to measure

        DebugTimer.Stop();
    }
}

Example output:

DebugTimer - Elapsed:       12 ms | UserService - GetUsers

Usage with int tag

using Pozitron.Diagnostics;

public sealed class ReportService
{
    public void BuildReport()
    {
        DebugTimer.Start(1);
        // code to measure

        DebugTimer.Start(2);
        // inner code to measure
        DebugTimer.Stop(2);

        DebugTimer.Stop(1);
    }
}

Example output:

DebugTimer - Elapsed:       10 ms | ReportService - BuildReport - 2
DebugTimer - Elapsed:       31 ms | ReportService - BuildReport - 1

Usage with string tag

using Pozitron.Diagnostics;

public sealed class ImportService
{
    public void LoadData()
    {
        DebugTimer.Start("Outer");
        // code to measure

        DebugTimer.Start("Inner");
        // inner code to measure
        DebugTimer.Stop("Inner");

        DebugTimer.Stop("Outer");
    }
}

Example output:

DebugTimer - Elapsed:       10 ms | ReportService - BuildReport - Inner
DebugTimer - Elapsed:       31 ms | ReportService - BuildReport - Outer

Global key usage across different classes/methods

using Pozitron.Diagnostics;

public sealed class JobCoordinator
{
    public static string StartJob(string jobId)
    {
        var key = $"JobPipeline - {jobId}";
        DebugTimer.StartGlobal(key);
        return key;
    }
}

public sealed class JobWorker
{
    public static void FinishJob(string key)
    {
        // potentially in another class/method/layer
        DebugTimer.StopGlobal(key);
    }
}

Example output:

DebugTimer - Elapsed:      203 ms | JobPipeline - 42

Custom logger

using Pozitron.Diagnostics;

DebugTimer.Initialize((template, source, elapsedMs, key) =>
{
    Console.WriteLine($"{source}: {elapsedMs,8} ms | {key}");
});

Serilog example:

using Pozitron.Diagnostics;
using Serilog;

DebugTimer.Initialize(Log.Information);

Notes

  • Use matching Start / Stop tags and caller context.
  • Start called multiple times for the same key restarts the timer.
  • Stop for a missing key does nothing.
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.6.0 146 4/9/2026

Refer to Releases page for details.
     https://github.com/fiseni/DebugTimer/releases