MCPcopy Create free account
hub / github.com/Rich-Harris/magic-string / Stats

Class Stats

src/utils/Stats.ts:3–24  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1import process from 'node:process'
2
3export default class Stats {
4 declare startTimes: Record<string, [number, number]>;
5 [label: string]: unknown;
6
7 constructor() {
8 Object.defineProperties(this, {
9 startTimes: { value: {} },
10 })
11 }
12
13 time(label: string): void {
14 this.startTimes[label] = process.hrtime()
15 }
16
17 timeEnd(label: string): void {
18 const elapsed = process.hrtime(this.startTimes[label])
19
20 if (!this[label])
21 this[label] = 0
22 this[label] = (this[label] as number) + elapsed[0] * 1e3 + elapsed[1] * 1e-6
23 }
24}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected