Jacky Zhao
2024-02-02 3231ce6e7970dd0bc79c33aa8bc09cfa9ab59d09
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import chalk from "chalk"
import pretty from "pretty-time"
 
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 chalk.yellow(pretty(process.hrtime(this.evts[evtName ?? "start"])))
  }
}