MCPcopy
hub / github.com/angular/angular / benchmarkRun

Function benchmarkRun

modules/ssr-benchmarks/run-benchmark.ts:52–90  ·  view source on GitHub ↗

* * @param rowCount Number of rows rendered in the App * @param renderingCount Number of times the app will be rendered

(rowCount: number, renderingCount: number)

Source from the content-addressed store, hash-verified

50 * @param renderingCount Number of times the app will be rendered
51 */
52async 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
92function durationToString(duration: number) {
93 return `${duration.toFixed(1)}ms`;

Callers 1

mainFunction · 0.85

Calls 12

initDataFunction · 0.90
renderFunction · 0.90
durationToStringFunction · 0.85
reduceMethod · 0.80
mapMethod · 0.80
getMethod · 0.65
joinMethod · 0.65
logMethod · 0.65
entriesMethod · 0.45
maxMethod · 0.45
minMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…