(create: () => void, destroy: () => void, name: string)
| 38 | } |
| 39 | |
| 40 | export function profile(create: () => void, destroy: () => void, name: string) { |
| 41 | return function () { |
| 42 | // 'console.profile' is experimental and was removed from DOM lib in TS 3.9 |
| 43 | (window.console as any).profile(name); |
| 44 | const noOfRuns = 150; |
| 45 | let durations: number[] = []; |
| 46 | let count = 0; |
| 47 | while (count++ < noOfRuns) { |
| 48 | const start = window.performance.now(); |
| 49 | create(); |
| 50 | const end = window.performance.now() - start; |
| 51 | durations.push(end); |
| 52 | destroy(); |
| 53 | } |
| 54 | // 'console.profileEnd' is experimental and was removed from DOM lib in TS 3.9 |
| 55 | (window.console as any).profileEnd(); |
| 56 | reportProfileResults(durations, noOfRuns); |
| 57 | }; |
| 58 | } |
| 59 | |
| 60 | function reportProfileResults(durations: number[], count: number) { |
| 61 | const totalDuration = durations.reduce((soFar: number, duration: number) => soFar + duration, 0); |
no test coverage detected
searching dependent graphs…