| 42 | } |
| 43 | |
| 44 | function measure( |
| 45 | name: string, |
| 46 | startMarkOrOptions?: string | MeasureOptions, |
| 47 | endMark?: string, |
| 48 | ): void { |
| 49 | let startTime: number |
| 50 | let duration: number |
| 51 | |
| 52 | if (typeof startMarkOrOptions === 'string') { |
| 53 | const start = marks.get(startMarkOrOptions) |
| 54 | const end = endMark ? marks.get(endMark) : now() |
| 55 | startTime = start ?? now() |
| 56 | duration = (end ?? now()) - startTime |
| 57 | } else if (startMarkOrOptions && typeof startMarkOrOptions === 'object') { |
| 58 | startTime = startMarkOrOptions.start ?? 0 |
| 59 | duration = (startMarkOrOptions.end ?? now()) - startTime |
| 60 | } else { |
| 61 | startTime = 0 |
| 62 | duration = now() |
| 63 | } |
| 64 | |
| 65 | measures.set(name, { name, startTime, duration }) |
| 66 | } |
| 67 | |
| 68 | interface MeasureOptions { |
| 69 | start?: number |