---
title: SAIF.Framework.CodeTimer overview
summary: High-level purpose, scope, and responsibilities for this library.
status: draft
owner: <owner>
last_reviewed: 2026-07-23
library: SAIF.Framework.CodeTimer
reference_type: package
---

# SAIF.Framework.CodeTimer overview

> **Documentation context:** Packaged Component (NuGet)

SAIF.Framework.CodeTimer is a lightweight, in-process, hierarchical code-timing/profiling utility exposed through a static `CodeTimer` façade. It has no dependency on the SAIF BOF business-object framework and no web layer in the compiled assembly.

## Purpose
- Provide a simple, static API that instrumented code can call to start and stop named or method-scoped timers, optionally nested in a parent/child hierarchy, and later retrieve aggregated timing statistics.
- Consumed directly by any code in the repository (or by code in packages that bundle this library) that wants lightweight, in-process performance instrumentation without adding an external profiling dependency.*

## Responsibilities
- Provide a static entry point (`CodeTimer`) for starting, stopping, and resetting named or method-scoped timers, optionally organized in a hierarchical parent/child key structure.
- Gate timing collection through a global enable switch (`CodeTimer.Enabled`) and an optional per-method `CodeTimerAttribute` flag.
- Accumulate per-timer statistics (elapsed, shortest, longest, quantity, captured spans) in `CodeTimerEntry` records held in a static dictionary.
- Transform the flat, `;`-delimited hierarchical key space into a tree of `CodeTimerItem` nodes and serialize that tree to XML.
- Provide a simple value type (`CustomTimeSpan`) capturing one timed span's start/stop/duration, and a comparer (`CodeTimerItemSorter`) for ordering result items.

## Key components
- `CodeTimer`: static façade; the sole public entry point for starting, stopping, resetting, and retrieving timer results.
- `CodeTimerAttribute`: method-level attribute used to toggle timing per instrumented method.
- `CodeTimerEntry`: per-timer running state (start/stop timestamps, elapsed, longest/shortest, span history).
- `CodeTimerResult`: internal reporting component that builds a `CodeTimerItem` tree from the raw timer dictionary and serializes it to XML or console text.
- `CodeTimerItem`: hierarchical result node used only for reporting output.
- `CodeTimerItemSorter`: comparer for ordering `CodeTimerItem` collections.
- `CustomTimeSpan`: value holder for one timed interval.

## Related documentation
- [Index](index.md)
- [Architecture](architecture.md)
- [Dependencies](dependencies.md)
- [Operations and processes](operations-processes.md)
- [Business rules](business-rules.md)
- [Configuration](configuration.md)
- [API reference](api/index.md)

> **Note:** Statements marked with * were inferred from code structure, naming conventions, or
> contextual evidence where direct confirmation was not available in source artifacts. Statements
> marked with ** could not be confirmed; treat as unknown until verified.

## Sources
- SAIF.Framework.CodeTimer\SAIF.Framework.CodeTimer\CodeTimer.cs
- SAIF.Framework.CodeTimer\SAIF.Framework.CodeTimer\CodeTimerAttribute.cs
- SAIF.Framework.CodeTimer\SAIF.Framework.CodeTimer\CodeTimerEntry.cs
- SAIF.Framework.CodeTimer\SAIF.Framework.CodeTimer\CodeTimerItem.cs
- SAIF.Framework.CodeTimer\SAIF.Framework.CodeTimer\CodeTimerItemSorter.cs
- SAIF.Framework.CodeTimer\SAIF.Framework.CodeTimer\CodeTimerResult.cs
- SAIF.Framework.CodeTimer\SAIF.Framework.CodeTimer\CustomTimeSpan.cs
- SAIF.Framework.CodeTimer\SAIF.Framework.CodeTimer\SAIF.Framework.CodeTimer.csproj
