8000 perf(core): use multiple directives in host bindings micro benchmark … · angular/angular@5bc39f8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5bc39f8

Browse files
AndrewKushniratscott
authored andcommitted
perf(core): use multiple directives in host bindings micro benchmark (#35736)
This commit updates the host bindings micro benchmark to run tests with mutliple directives (where each directive contains host bindings). The number of directives is configurable as a constant in the micro benchmark file. This change is needed to have an ability to measure/compare perf in different scenarios. PR Close #35736
1 parent ef75875 commit 5bc39f8

File tree

1 file changed

+28
-18
lines changed
  • packages/core/test/render3/perf/host_binding

1 file changed

+28
-18
lines changed

packages/core/test/render3/perf/host_binding/index.ts

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ import {TAttributes} from '../../../../src/render3/interfaces/node';
1111
import {createBenchmark} from '../micro_bench';
1212
import {setupTestHarness} from '../setup';
1313

14-
`
14+
// Number of Directives with Host Binding and Host Listener
15+
// that should be generated for one element in a template.
16+
const HOST_BINDING_DIRS_COUNT = 100;
17+
18+
function generateHostBindingDirDef() {
19+
`
1520
@Directive({
1621
selector: '[hostBindingDir]'
1722
})
@@ -25,24 +30,26 @@ import {setupTestHarness} from '../setup';
2530
onClick(event: any): void {}
2631
}
2732
`;
28-
class HostBindingDir {
29-
static ɵfac() { return new HostBindingDir(); }
30-
static ɵdir = ɵɵdefineDirective({
31-
type: HostBindingDir,
32-
selectors: [['', 'hostBindingDir', '']],
33-
hostVars: 2,
34-
hostBindings: function(rf: RenderFlags, ctx: any) {
35-
if (rf & 1) {
36-
ɵɵlistener('click', function() { return ctx.onClick(); });
37-
}
38-
if (rf & 2) {
39-
ɵɵhostProperty('data-a', ctx.exp);
33+
class HostBindingDir {
34+
static ɵfac() { return new HostBindingDir(); }
35+
static ɵdir = ɵɵdefineDirective({
36+
type: HostBindingDir,
37+
selectors: [['', 'hostBindingDir', '']],
38+
hostVars: 2,
39+
hostBindings: function(rf: RenderFlags, ctx: any) {
40+
if (rf & 1) {
41+
ɵɵlistener('click', function() { return ctx.onClick(); });
42+
}
43+
if (rf & 2) {
44+
ɵɵhostProperty('data-a', ctx.exp);
45+
}
4046
}
41-
}
42-
});
47+
});
4348

44-
exp = 'string-exp';
45-
onClick() {}
49+
exp = 'string-exp';
50+
onClick() {}
51+
}
52+
return HostBindingDir.ɵdir;
4653
}
4754

4855
`
@@ -56,7 +63,10 @@ function componentTemplateFn(rf: RenderFlags, ctx: any) {
5663

5764
const context: any = {};
5865
const consts: TAttributes[] = [['hostBindingDir', '']];
59-
const directives: DirectiveDefList = [HostBindingDir.ɵdir];
66+
const directives: DirectiveDefList = [];
67+
for (let i = 0; i < HOST_BINDING_DIRS_COUNT; i++) {
68+
directives.push(generateHostBindingDirDef());
69+
}
6070
const harness = setupTestHarness(componentTemplateFn, 1, 0, 1000, context, consts, directives);
6171

6272
// Benchmark host bindings execution in *creation* mode

0 commit comments

Comments
 (0)
0