This repository has been archived on 2024-09-06. You can view files and clone it, but cannot push or open issues or pull requests.
quartz-wiki/quartz/util/perf.ts

20 lines
401 B
TypeScript
Raw Permalink Normal View History

2024-01-10 14:39:54 +08:00
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"])))
}
}