MCPcopy Create free account
hub / github.com/angular/components / PerformanceDemo

Class PerformanceDemo

src/dev-app/performance/performance-demo.ts:45–153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43 ],
44})
45export class PerformanceDemo implements AfterViewInit {
46 /** Controls the rendering of components. */
47 show = false;
48
49 /** The number of times metrics will be gathered. */
50 sampleSize = 100;
51
52 /** The number of components being rendered. */
53 componentCount = 100;
54
55 /** A flat array of every sample recorded. */
56 allSamples: number[] = [];
57
58 /** Used to disable benchmark controls while a benchmark is being run. */
59 isRunningBenchmark = false;
60
61 /** The columns in the metrics table. */
62 displayedColumns: string[] = ['index', 'time'];
63
64 /** Basically the same thing as allSamples but organized as a mat-table data source. */
65 dataSource = new MatTableDataSource<{index: number; time: string}>();
66
67 /** The average plus/minus the stdev. */
68 computedResults = '';
69
70 /** Used in an `@for` to render the desired number of comonents. */
71 componentArray = [].constructor(this.componentCount);
72
73 private _injector = inject(Injector);
74
75 readonly cdr = inject(ChangeDetectorRef);
76
77 /** The standard deviation of the recorded samples. */
78 get stdev(): number | undefined {
79 if (!this.allSamples.length) {
80 return undefined;
81 }
82 return Math.sqrt(
83 this.allSamples.map(x => Math.pow(x - this.mean!, 2)).reduce((a, b) => a + b) /
84 this.allSamples.length,
85 );
86 }
87
88 /** The average value of the recorded samples. */
89 get mean(): number | undefined {
90 if (!this.allSamples.length) {
91 return undefined;
92 }
93 return this.allSamples.reduce((a, b) => a + b) / this.allSamples.length;
94 }
95
96 @ViewChild(MatPaginator) paginator?: MatPaginator;
97
98 ngAfterViewInit() {
99 this.dataSource.paginator = this.paginator!;
100 }
101
102 getTotalRenderTime(): string {

Callers

nothing calls this directly

Calls 1

constructorMethod · 0.45

Tested by

no test coverage detected