* * @param rowCount Number of rows rendered in the App * @param renderingCount Number of times the app will be rendered
(rowCount: number, renderingCount: number)
| 50 | * @param renderingCount Number of times the app will be rendered |
| 51 | */ |
| 52 | async function benchmarkRun(rowCount: number, renderingCount: number) { |
| 53 | const measures: Map<string, number[]> = new Map(); |
| 54 | initData(rowCount); |
| 55 | |
| 56 | // Rendering & profiling |
| 57 | for (let i = 0; i < renderingCount; i++) { |
| 58 | await render(DISABLE_DOM_EMULATION); |
| 59 | storePerformanceLogOfCurrentRun(measures); |
| 60 | } |
| 61 | |
| 62 | const totals = measures.get(`${PERFORMANCE_MARK_PREFIX}:renderApplication`)!; |
| 63 | const avgTotals = totals.reduce((acc, val) => acc + val, 0) / totals.length; |
| 64 | |
| 65 | let maxNameLength = 0; |
| 66 | const table = [...measures.entries()] |
| 67 | .map(([name, durations]) => { |
| 68 | name = name.substring(PERFORMANCE_MARK_PREFIX.length + 1); |
| 69 | const level = levels.get(name) ?? 0; |
| 70 | name = `${new Array(level + 1).join(' ')} ${level ? '└ ' : ''}${name}`; |
| 71 | maxNameLength = Math.max(name.length, maxNameLength); |
| 72 | const avg = durations.reduce((acc, val) => acc + val, 0) / durations.length; |
| 73 | const avgStr = durationToString(avg); |
| 74 | const percentage = `${((avg / avgTotals) * 100).toFixed(1)}%`; |
| 75 | const min = durationToString(Math.min(...durations)); |
| 76 | const max = durationToString(Math.max(...durations)); |
| 77 | return {name, min, average: avgStr, percentage, max}; |
| 78 | }) |
| 79 | .map(({name, ...rest}) => { |
| 80 | // We need this because Node18 aligns text in the middle of the column instead of left). |
| 81 | const spaces = maxNameLength - name.length; |
| 82 | |
| 83 | return {name: `${name}${' '.repeat(spaces)}`, ...rest}; |
| 84 | }); |
| 85 | |
| 86 | // Logging the profiling result as a table |
| 87 | console.log(`=== table with ${rowCount} rows, with ${renderingCount} renders ===`); |
| 88 | console.table(table); |
| 89 | console.log('\n', '\n'); |
| 90 | } |
| 91 | |
| 92 | function durationToString(duration: number) { |
| 93 | return `${duration.toFixed(1)}ms`; |
no test coverage detected
searching dependent graphs…