-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(benchmarks): setup for benchmarking components #19320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
load("@npm_angular_dev_infra_private//benchmark/component_benchmark:component_benchmark.bzl", "component_benchmark") | ||
wagnermaciel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# 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 = ":checkbox.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/checkbox", | ||
"//src/cdk/a11y", | ||
], | ||
ng_srcs = [":app.module.ts"], | ||
prefix = "", | ||
styles = ["//src/material/prebuilt-themes:indigo-pink"], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. 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 {A11yModule} from '@angular/cdk/a11y'; | ||
import {Component, NgModule, ViewEncapsulation} from '@angular/core'; | ||
import {BrowserModule} from '@angular/platform-browser'; | ||
import {MatCheckboxModule} from '@angular/material/checkbox'; | ||
|
||
/** | ||
* @title Checkbox benchmark component. | ||
*/ | ||
@Component({ | ||
selector: 'app-root', | ||
template: ` | ||
<button id="show" (click)="show()">Show</button> | ||
<button id="hide" (click)="hide()">Hide</button> | ||
<button id="indeterminate" (click)="indeterminate()">Indeterminate</button> | ||
|
||
<ng-container *ngIf="isVisible"> | ||
<mat-checkbox | ||
[checked]="isChecked" | ||
[indeterminate]="isIndeterminate" | ||
(change)="toggleIsChecked()"> | ||
Check me!</mat-checkbox> | ||
</ng-container> | ||
`, | ||
encapsulation: ViewEncapsulation.None, | ||
styleUrls: ['//src/material/core/theming/prebuilt/indigo-pink.css'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you confirm if that actually works? I wouldn't know of any resolution code that supports Bazel labels. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @devversion Yeah, it works. Removing it breaks the styles. Kinda strange now that you mention it... @jelbourn Does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have no idea how this would work. @devversion and @wagnermaciel could you pair to figure out the best way to set this up? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you think about the impact of using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just checked. It works only with Regardless of that though, I think we should not load the theme as part of the component factory. That will cause deviations in benchmarks as the theme will be loaded deferred and through Angular. I still think we should implement asset injection. I think we could merge this in the interim. Asset injection would require upstream changes in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That explains it! Yeah, I agree that we can leave this for now and change it to an asset in a follow-up. @wagnermaciel can you add a TODO and file an issue for yourself? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
}) | ||
export class CheckboxBenchmarkApp { | ||
isChecked = false; | ||
isVisible = false; | ||
isIndeterminate = false; | ||
|
||
show() { this.isVisible = true; } | ||
hide() { this.isVisible = false; } | ||
indeterminate() { this.isIndeterminate = true; } | ||
toggleIsChecked() { this.isChecked = !this.isChecked; } | ||
} | ||
|
||
|
||
@NgModule({ | ||
declarations: [CheckboxBenchmarkApp], | ||
imports: [ | ||
A11yModule, | ||
BrowserModule, | ||
MatCheckboxModule, | ||
], | ||
providers: [], | ||
bootstrap: [CheckboxBenchmarkApp] | ||
}) | ||
export class AppModule {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. 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('checkbox overview performance benchmarks', () => { | ||
beforeAll(() => { | ||
browser.rootEl = '#root'; | ||
}); | ||
|
||
it('renders a checked checkbox', async() => { | ||
await runBenchmark({ | ||
id: 'checkbox-overview-render-checked', | ||
url: '', | ||
ignoreBrowserSynchronization: true, | ||
params: [], | ||
setup: async () => { | ||
await $('#show').click(); | ||
wagnermaciel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
await $('mat-checkbox').click(); | ||
}, | ||
prepare: async () => { | ||
expect(await $('mat-checkbox input').isSelected()) | ||
.toBe(true, 'The checkbox should be in a selected state.'); | ||
await $('#hide').click(); | ||
}, | ||
work: async () => await $('#show').click() | ||
}); | ||
}); | ||
|
||
it('renders an unchecked checkbox', async() => { | ||
await runBenchmark({ | ||
id: 'checkbox-overview-render-unchecked', | ||
url: '', | ||
ignoreBrowserSynchronization: true, | ||
params: [], | ||
setup: async() => await $('#show').click(), | ||
prepare: async () => { | ||
expect(await $('mat-checkbox input').isSelected()) | ||
.toBe(false, 'The checkbox should be in an unselected state.'); | ||
await $('#hide').click(); | ||
}, | ||
work: async () => await $('#show').click() | ||
}); | ||
}); | ||
|
||
it('renders an indeterminate checkbox', async() => { | ||
await runBenchmark({ | ||
id: 'checkbox-overview-render-indeterminate', | ||
url: '', | ||
ignoreBrowserSynchronization: true, | ||
params: [], | ||
setup: async() => { | ||
await $('#show').click(); | ||
await $('#indeterminate').click(); | ||
}, | ||
prepare: async () => { | ||
expect(await $('mat-checkbox input').getAttribute('indeterminate')) | ||
.toBe('true', 'The checkbox should be in an indeterminate state'); | ||
await $('#hide').click(); | ||
}, | ||
work: async () => await $('#show').click() | ||
}); | ||
}); | ||
|
||
it('updates from unchecked to checked', async() => { | ||
await runBenchmark({ | ||
id: 'checkbox-overview-click-unchecked-to-checked', | ||
url: '', | ||
ignoreBrowserSynchronization: true, | ||
params: [], | ||
setup: async () => { | ||
await $('#show').click(); | ||
await $('mat-checkbox').click(); | ||
}, | ||
prepare: async () => { | ||
await $('mat-checkbox').click(); | ||
expect(await $('mat-checkbox input').isSelected()) | ||
.toBe(false, 'The checkbox should be in an unchecked state.'); | ||
}, | ||
work: async () => await $('mat-checkbox').click(), | ||
}); | ||
}); | ||
|
||
it('updates from checked to unchecked', async() => { | ||
await runBenchmark({ | ||
id: 'checkbox-overview-click-checked-to-unchecked', | ||
url: '', | ||
ignoreBrowserSynchronization: true, | ||
params: [], | ||
setup: async () => await $('#show').click(), | ||
prepare: async () => { | ||
await $('mat-checkbox').click(); | ||
expect(await $('mat-checkbox input').isSelected()) | ||
.toBe(true, 'The checkbox should be in a checked state.'); | ||
}, | ||
work: async () => await $('mat-checkbox').click(), | ||
}); | ||
}); | ||
}); |
Uh oh!
There was an error while loading. Please reload this page.