Skip to content

Commit 01ca561

Browse files
committed
feat(benchmarks): setup for benchmarking components
* set up components repo to use dev-infra benchmarking tools * created first set of benchmark tests for mat-checkbox
1 parent 4d7ffaa commit 01ca561

File tree

7 files changed

+351
-3
lines changed

7 files changed

+351
-3
lines changed

WORKSPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,7 @@ rbe_autoconfig(
129129
# a specific Linux kernel that comes with "libx11" in order to run headless browser tests.
130130
repository = "google/rbe-ubuntu16-04-webtest",
131131
)
132+
133+
load("@npm_angular_dev_infra_private//benchmark/browsers:browser_repositories.bzl", "browser_repositories")
134+
135+
browser_repositories()

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"yarn": ">= 1.0.0"
1414
},
1515
"scripts": {
16-
"postinstall": "node tools/postinstall/apply-patches.js && ngcc --properties main --create-ivy-entry-points && node tools/postinstall/update-ngcc-main-fields.js",
16+
"postinstall": "node tools/postinstall/apply-patches.js && ngcc --properties module main --create-ivy-entry-points && node tools/postinstall/update-ngcc-main-fields.js",
1717
"build": "node ./scripts/build-packages-dist.js",
1818
"bazel": "bazelisk",
1919
"bazel:buildifier": "find . -type f \\( -name \"*.bzl\" -or -name WORKSPACE -or -name BUILD -or -name BUILD.bazel \\) ! -path \"*/node_modules/*\" | xargs buildifier -v --warnings=attr-cfg,attr-license,attr-non-empty,attr-output-default,attr-single-file,constant-glob,ctx-args,depset-iteration,depset-union,dict-concatenation,duplicated-name,filetype,git-repository,http-archive,integer-division,load,load-on-top,native-build,native-package,output-group,package-name,package-on-top,redefined-variable,repository-name,same-origin-load,string-iteration,unused-variable,unsorted-dict-items,out-of-order-load",
@@ -45,18 +45,23 @@
4545
},
4646
"version": "9.2.0-next.0",
4747
"dependencies": {
48+
"@angular/benchpress": "^0.2.0",
49+
"@angular/dev-infra": "file:../dev-infra",
50+
"@angular-devkit/build-optimizer": "^0.900.6",
4851
"@angular/animations": "^9.1.0-next.4",
4952
"@angular/common": "^9.1.0-next.4",
5053
"@angular/compiler": "^9.1.0-next.4",
5154
"@angular/core": "^9.1.0-next.4",
5255
"@angular/elements": "^9.1.0-next.4",
5356
"@angular/forms": "^9.1.0-next.4",
5457
"@angular/platform-browser": "^9.1.0-next.4",
58+
"@bazel/terser": "^1.4.1",
5559
"@types/googlemaps": "^3.37.0",
5660
"@types/youtube": "^0.0.38",
5761
"@webcomponents/custom-elements": "^1.1.0",
5862
"core-js": "^2.6.9",
5963
"material-components-web": "6.0.0-canary.d5808057f.0",
64+
"node-uuid": "^1.4.8",
6065
"rxjs": "^6.5.3",
6166
"systemjs": "0.19.43",
6267
"tslib": "^1.10.0",

src/components-examples/material/checkbox/benchmark-driver.ts

Whitespace-only changes.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
load("@npm_angular_dev_infra_private//benchmark/component_benchmark:component_benchmark.bzl", "component_benchmark")
2+
3+
genrule(
4+
name = "indigo-pink",
5+
srcs = ["//src/material/core:theming/prebuilt/indigo-pink.css"],
6+
outs = ["styles.css"],
7+
cmd = "cp $< $@",
8+
)
9+
10+
# todo(wagnermaciel): If assets are defined and no index.html is provided, throw error with clear error message.
11+
component_benchmark(
12+
name = "benchmark",
13+
driver = ":checkbox.perf-spec.ts",
14+
driver_deps = [
15+
"@npm//@angular/dev-infra",
16+
"@npm//protractor",
17+
"@npm//@types/jasmine",
18+
],
19+
ng_deps = [
20+
"@npm//@angular/core",
21+
"@npm//@angular/platform-browser",
22+
"//src/components-examples/material/checkbox",
23+
"//src/cdk/a11y",
24+
],
25+
ng_srcs = [":app.module.ts"],
26+
styles = [":indigo-pink"],
27+
prefix = "",
28+
)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
import { A11yModule } from '@angular/cdk/a11y';
9+
import { Component, NgModule, ViewChild } from '@angular/core';
10+
import { BrowserModule } from '@angular/platform-browser';
11+
import { MatCheckboxModule, MatCheckbox } from '@angular/material/checkbox';
12+
13+
/**
14+
* @title Checkbox benchmark component.
15+
*/
16+
@Component({
17+
selector: 'app-root',
18+
template: `
19+
<button id="show" (click)="show()">Show</button>
20+
<button id="hide" (click)="hide()">Hide</button>
21+
<button id="indeterminate" (click)="indeterminate()">Indeterminate</button>
22+
23+
<ng-container *ngIf="isVisible">
24+
<mat-checkbox
25+
[checked]="isChecked"
26+
[(indeterminate)]="isIndeterminate"
27+
(change)="toggleIsChecked()"
28+
>Check me!</mat-checkbox>
29+
</ng-container>
30+
`,
31+
styles: [],
32+
})
33+
export class CheckboxBenchmarkApp {
34+
isChecked = false;
35+
isVisible = false;
36+
isIndeterminate = false;
37+
38+
show() { this.isVisible = true; }
39+
hide() { this.isVisible = false; }
40+
indeterminate() { this.isIndeterminate = true; }
41+
toggleIsChecked() { this.isChecked = !this.isChecked; }
42+
}
43+
44+
45+
@NgModule({
46+
declarations: [CheckboxBenchmarkApp],
47+
imports: [
48+
A11yModule,
49+
BrowserModule,
50+
MatCheckboxModule,
51+
],
52+
providers: [],
53+
bootstrap: [CheckboxBenchmarkApp]
54+
})
55+
export class AppModule {}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {$, browser} from 'protractor';
10+
import {runBenchmark} from '@angular/dev-infra/benchmark/driver-utilities';
11+
12+
describe('checkbox overview performance benchmarks', () => {
13+
beforeAll(() => {
14+
browser.rootEl = '#root';
15+
});
16+
17+
it('render (checked)', async() => {
18+
await runBenchmark({
19+
id: 'checkbox-overview-render-checked',
20+
url: '',
21+
ignoreBrowserSynchronization: true,
22+
params: [],
23+
setup: async () => {
24+
await $('#show').click();
25+
await $('mat-checkbox').click();
26+
},
27+
prepare: async () => {
28+
expect(await $('mat-checkbox input').isSelected())
29+
.toBe(true, 'The checkbox should be in a selected state.');
30+
await $('#hide').click();
31+
},
32+
work: async () => await $('#show').click()
33+
});
34+
});
35+
36+
it('render (unchecked)', async() => {
37+
await runBenchmark({
38+
id: 'checkbox-overview-render-unchecked',
39+
url: '',
40+
ignoreBrowserSynchronization: true,
41+
params: [],
42+
setup: async() => await $('#show').click(),
43+
prepare: async () => {
44+
expect(await $('mat-checkbox input').isSelected())
45+
.toBe(false, 'The checkbox should be in an unselected state.');
46+
await $('#hide').click();
47+
},
48+
work: async () => await $('#show').click()
49+
});
50+
});
51+
52+
it('render (indeterminate)', async() => {
53+
await runBenchmark({
54+
id: 'checkbox-overview-render-indeterminate',
55+
url: '',
56+
ignoreBrowserSynchronization: true,
57+
params: [],
58+
setup: async() => {
59+
await $('#show').click();
60+
await $('#indeterminate').click();
61+
},
62+
prepare: async () => {
63+
expect(await $('mat-checkbox input').getAttribute('indeterminate'))
64+
.toBe('true', 'The checkbox should be in an indeterminate state');
65+
await $('#hide').click();
66+
},
67+
work: async () => await $('#show').click()
68+
});
69+
});
70+
71+
it('click (unchecked -> checked)', async() => {
72+
await runBenchmark({
73+
id: 'checkbox-overview-click-unchecked-to-checked',
74+
url: '',
75+
ignoreBrowserSynchronization: true,
76+
params: [],
77+
setup: async () => {
78+
await $('#show').click();
79+
await $('mat-checkbox').click();
80+
},
81+
prepare: async () => {
82+
await $('mat-checkbox').click();
83+
expect(await $('mat-checkbox input').isSelected())
84+
.toBe(false, 'The checkbox should be in an unchecked state.');
85+
},
86+
work: async () => await $('mat-checkbox').click(),
87+
});
88+
});
89+
90+
it('click (checked -> unchecked)', async() => {
91+
await runBenchmark({
92+
id: 'checkbox-overview-click-checked-to-unchecked',
93+
url: '',
94+
ignoreBrowserSynchronization: true,
95+
params: [],
96+
setup: async () => await $('#show').click(),
97+
prepare: async () => {
98+
await $('mat-checkbox').click();
99+
expect(await $('mat-checkbox input').isSelected())
100+
.toBe(true, 'The checkbox should be in a checked state.');
101+
},
102+
work: async () => await $('mat-checkbox').click(),
103+
});
104+
});
105+
});

0 commit comments

Comments
 (0)