2023-07-23 07:27:41 +07:00
|
|
|
import chalk from "chalk"
|
|
|
|
import pretty from "pretty-time"
|
2023-05-30 22:02:20 +07:00
|
|
|
|
|
|
|
export class PerfTimer {
|
|
|
|
evts: { [key: string]: [number, number] }
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
this.evts = {}
|
2023-07-23 07:27:41 +07:00
|
|
|
this.addEvent("start")
|
2023-05-30 22:02:20 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
addEvent(evtName: string) {
|
|
|
|
this.evts[evtName] = process.hrtime()
|
|
|
|
}
|
|
|
|
|
|
|
|
timeSince(evtName?: string): string {
|
2023-07-23 07:27:41 +07:00
|
|
|
return chalk.yellow(pretty(process.hrtime(this.evts[evtName ?? "start"])))
|
2023-05-30 22:02:20 +07:00
|
|
|
}
|
|
|
|
}
|