Performance Utility
PerformanceUtility measures and logs how long a code block takes to run, built on performance.now() (millisecond resolution). BaseApplication uses PerformanceUtility.executeWithMeasure internally to time component, controller, and datasource registration during startup.
The old function names (executeWithPerformanceMeasure, getPerformanceCheckpoint, getExecutedPerformance) are removed; devz codemod namespace-functions moves your calls.
In one example
typescript
import { PerformanceUtility } from '@venizia/ignis-helpers';
await PerformanceUtility.executeWithMeasure({
logger: this.logger,
scope: this.registerComponents.name,
description: 'Register application components',
task: async () => {
// ... logic to register components
},
});[RegisterComponents] START | Register application components ...
[RegisterComponents] DONE | Register application components | Took: 12.3456 (ms)Methods
| Method | Signature | What it does |
|---|---|---|
PerformanceUtility.executeWithMeasure | executeWithMeasure<R>(opts: { logger?: ILogger; level?: string; description?: string; args?: any; scope: string; task: Function }): Promise<R> | Runs task (sync or async), logging a START line before and a DONE line after with the elapsed time. Resolves to whatever task returns. |
PerformanceUtility.getCheckpoint | getCheckpoint(): number | Returns performance.now() - a starting timestamp to pass to getExecuted. |
PerformanceUtility.getExecuted | getExecuted(opts: { from: number; digit?: number }): number | Elapsed milliseconds since from, rounded to digit places (default 6). |
Notes
- Defaults:
loggerfalls back toconsole,levelto'debug',descriptionto'Executing'. args, when provided, are logged as JSON (%j) on both theSTARTandDONElines - handy for correlating a specific call's timing.taskis wrapped inPromise.resolve(), so a plain synchronous function works exactly like anasyncone.- Prefer the checkpoint pair for granular, multi-point measurements inside a single function, where wrapping the whole thing in
executeWithMeasurewould not isolate the segment you care about.
See also
- Utilities Overview - all utility functions
- Logger - the
ILoggertype accepted byPerformanceUtility.executeWithMeasure
Files: