| 33 | } |
| 34 | |
| 35 | function logTiming(start: number, funcName: string): void { |
| 36 | const end = performance.now(); |
| 37 | const time = end - start; |
| 38 | |
| 39 | if (!timings.has(funcName)) { |
| 40 | timings.set(funcName, []); |
| 41 | } |
| 42 | |
| 43 | const arr = timings.get(funcName) as number[]; |
| 44 | arr.push(time); |
| 45 | |
| 46 | console.log(`${funcName} took ${roundTo2(time)} ms`); |
| 47 | console.log(funcName, { |
| 48 | average: `${roundTo2(mean(arr))} ms`, |
| 49 | stdDev: `${roundTo2(stdDev(arr))} ms`, |
| 50 | min: `${roundTo2(Math.min(...arr))} ms`, |
| 51 | max: `${roundTo2(Math.max(...arr))} ms`, |
| 52 | count: arr.length, |
| 53 | }); |
| 54 | const endOverhead = performance.now(); |
| 55 | console.timeStamp( |
| 56 | `#${arr.length} ${funcName}`, |
| 57 | //@ts-expect-error chrome api thingy |
| 58 | start, |
| 59 | end, |
| 60 | funcName, |
| 61 | "monkeytype", |
| 62 | ); |
| 63 | console.timeStamp( |
| 64 | `#${arr.length} profiling overhead`, |
| 65 | //@ts-expect-error chrome api thingy |
| 66 | end, |
| 67 | endOverhead, |
| 68 | funcName, |
| 69 | "monkeytype", |
| 70 | ); |
| 71 | } |