Import
Profiler
Accumulates named timing measurements and produces a summary.
Constructor
| Property | Type | Default | Description |
|---|---|---|---|
namespace | string | — | Optional label to group measurements |
Methods
| Method | Returns | Description |
|---|---|---|
start(label) | void | Begins a timing measurement for the given label |
end(label) | void | Ends the measurement started with start(label) |
summary() | Record<string, number> or Record<string, Record<string, number>> | Returns accumulated timings. Flat when no namespace is set; namespaced otherwise. |
Example
Debug utilities
Standalone timing functions frombytekit/debug for one-off measurements without managing a Profiler instance.
createStopwatch
Creates a manual stopwatch for fine-grained control.
Options
| Property | Type | Default | Description |
|---|---|---|---|
label | string | — | Identifier for log output |
logger | Logger | — | Logger instance for automatic output |
precision | number | — | Decimal places for millisecond values |
autoLog | boolean | — | Automatically log the duration on stop() |
namespace | string | — | Prefix for log messages |
Stopwatch methods
| Method | Returns | Description |
|---|---|---|
stop() | number | Stops the timer and returns elapsed milliseconds |
elapsed() | number | Returns elapsed milliseconds without stopping |
log(context?) | number | Logs the elapsed time and returns it |
Example
withTiming
Wraps an async function and logs its execution time.
| Parameter | Type | Description |
|---|---|---|
label | string | Identifier for the measurement |
fn | () => Promise<T> | Async function to measure |
options | object | Same as stopwatch options |
Example
measureSync
Measures a synchronous function and returns its result.
Example
measureAsync
Measures an async function and returns both the result and the duration.
Example
captureDebug
Captures timing information for an async operation without a label.
Example
Choosing the right tool
Use Profiler when…
Use Profiler when…
You need to accumulate multiple named measurements across a workflow and produce a summary at the end — for example, profiling an entire request lifecycle.
Use createStopwatch when…
Use createStopwatch when…
You want manual start/stop control over a single measurement with optional automatic logging.
Use withTiming / measureSync / measureAsync when…
Use withTiming / measureSync / measureAsync when…
You want a one-liner that wraps an existing function call and logs or returns the duration.
Use captureDebug when…
Use captureDebug when…
You need a quick timing capture without labels or logging — useful in tests and diagnostics.