diff --git a/test/benchmarks/mdc/radio/BUILD.bazel b/test/benchmarks/mdc/radio/BUILD.bazel new file mode 100644 index 000000000000..18f52f7b81ef --- /dev/null +++ b/test/benchmarks/mdc/radio/BUILD.bazel @@ -0,0 +1,22 @@ +load("@npm_angular_dev_infra_private//benchmark/component_benchmark:component_benchmark.bzl", "component_benchmark") + +# TODO(wagnermaciel): Update this target to provide indigo-pink in a way that doesn't require having to import it with +# stylesUrls inside the components once `component_benchmark` supports asset injection. + +component_benchmark( + name = "benchmark", + driver = ":radio.perf-spec.ts", + driver_deps = [ + "@npm//@angular/dev-infra-private", + "@npm//protractor", + "@npm//@types/jasmine", + ], + ng_deps = [ + "@npm//@angular/core", + "@npm//@angular/platform-browser", + "//src/material-experimental/mdc-radio", + ], + ng_srcs = [":app.module.ts"], + prefix = "", + styles = ["//src/material-experimental/mdc-theming:indigo_pink_prebuilt"], +) diff --git a/test/benchmarks/mdc/radio/app.module.ts b/test/benchmarks/mdc/radio/app.module.ts new file mode 100644 index 000000000000..d1a9b15a3a3a --- /dev/null +++ b/test/benchmarks/mdc/radio/app.module.ts @@ -0,0 +1,65 @@ +/** + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import {Component, NgModule, ViewEncapsulation} from '@angular/core'; +import {BrowserModule} from '@angular/platform-browser'; +import {MatRadioModule} from '@angular/material-experimental/mdc-radio'; + +/** component: mdc-radio-button */ + +@Component({ + selector: 'app-root', + template: ` + + + + + + + + Option 1 + Option 2 + + + + Option 1 + Option 2 + Option 3 + Option 4 + Option 5 + Option 6 + Option 7 + Option 8 + Option 9 + Option 10 + + `, + encapsulation: ViewEncapsulation.None, + styleUrls: ['//src/material-experimental/mdc-theming/prebuilt/indigo-pink.css'], +}) +export class RadioBenchmarkApp { + isTwoVisible = false; + isTenVisible = false; + + showTwo() { this.isTwoVisible = true; } + hideTwo() { this.isTwoVisible = false; } + + showTen() { this.isTenVisible = true; } + hideTen() { this.isTenVisible = false; } +} + + +@NgModule({ + declarations: [RadioBenchmarkApp], + imports: [ + BrowserModule, + MatRadioModule, + ], + bootstrap: [RadioBenchmarkApp], +}) +export class AppModule {} diff --git a/test/benchmarks/mdc/radio/radio.perf-spec.ts b/test/benchmarks/mdc/radio/radio.perf-spec.ts new file mode 100755 index 000000000000..37acd08808c7 --- /dev/null +++ b/test/benchmarks/mdc/radio/radio.perf-spec.ts @@ -0,0 +1,50 @@ +/** + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import {$, browser} from 'protractor'; +import {runBenchmark} from '@angular/dev-infra-private/benchmark/driver-utilities'; + +describe('radio button performance benchmarks', () => { + beforeAll(() => { + browser.rootEl = '#root'; + }); + + it('renders two radio buttons', async() => { + await runBenchmark({ + id: 'render-two-radio-buttons', + url: '', + ignoreBrowserSynchronization: true, + params: [], + prepare: async () => await $('#hide-two').click(), + work: async () => await $('#show-two').click(), + }); + }); + + it('renders ten radio buttons', async() => { + await runBenchmark({ + id: 'render-ten-radio-buttons', + url: '', + ignoreBrowserSynchronization: true, + params: [], + prepare: async () => await $('#hide-ten').click(), + work: async () => await $('#show-ten').click(), + }); + }); + + it('changing between radio buttons', async() => { + await runBenchmark({ + id: 'click-radio-button', + url: '', + ignoreBrowserSynchronization: true, + params: [], + setup: async() => await $('#show-two').click(), + prepare: async() => await $('#btn-1').click(), + work: async () => await $('#btn-2').click(), + }); + }); +});