Michael Thomason
2025-11-01 2fdc8129b675d4e9090ba214a5a36646e630c817
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import pretty from "pretty-time"
import { styleText } from "util"
 
export class PerfTimer {
  evts: { [key: string]: [number, number] }
 
  constructor() {
    this.evts = {}
    this.addEvent("start")
  }
 
  addEvent(evtName: string) {
    this.evts[evtName] = process.hrtime()
  }
 
  timeSince(evtName?: string): string {
    return styleText("yellow", pretty(process.hrtime(this.evts[evtName ?? "start"])))
  }
}