Add timer

This commit is contained in:
Colin McDonnell
2025-12-04 10:56:45 -08:00
parent 6e337407a7
commit 22418b3714
2 changed files with 33 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
import { log } from "./cli.ts";
export class Timer {
private initialTimestamp: number;
private lastCheckpointTimestamp: number | null = null;
constructor() {
this.initialTimestamp = Date.now();
}
checkpoint(name: string): void {
const now = Date.now();
const duration = this.lastCheckpointTimestamp
? now - this.lastCheckpointTimestamp
: now - this.initialTimestamp;
log.info(`${name}: ${duration}ms`);
this.lastCheckpointTimestamp = now;
}
}