Skip to content

Commit

Permalink
perf(ivy): add new benchmark focused on template creation (#33511)
Browse files Browse the repository at this point in the history
PR Close #33511
  • Loading branch information
pkozlowski-opensource authored and atscott committed Oct 31, 2019
1 parent 4452d6d commit df1bef3
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/core/test/render3/perf/BUILD.bazel
Expand Up @@ -99,6 +99,19 @@ ng_benchmark(
bundle = ":noop_change_detection_lib",
)

ng_rollup_bundle(
name = "ng_template_lib",
entry_point = ":ng_template/index.ts",
deps = [
":perf_lib",
],
)

ng_benchmark(
name = "ng_template",
bundle = ":ng_template_lib",
)

ng_rollup_bundle(
name = "property_binding_lib",
entry_point = ":property_binding/index.ts",
Expand Down
60 changes: 60 additions & 0 deletions packages/core/test/render3/perf/ng_template/index.ts
@@ -0,0 +1,60 @@
/**
* @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 {ɵɵtemplate} from '../../../../src/render3/instructions/container';
import {createTNode, createTView} from '../../../../src/render3/instructions/shared';
import {RenderFlags} from '../../../../src/render3/interfaces/definition';
import {TNodeType, TViewNode} from '../../../../src/render3/interfaces/node';
import {createBenchmark} from '../micro_bench';
import {createAndRenderLView} from '../setup';

`<div>
<ng-template></ng-template>
<ng-template></ng-template>
<ng-template></ng-template>
<ng-template></ng-template>
<ng-template></ng-template>
<ng-template></ng-template>
<ng-template></ng-template>
<ng-template></ng-template>
<ng-template></ng-template>
<ng-template></ng-template>
</div>
</ng-template>`;
function testTemplate(rf: RenderFlags, ctx: any) {
if (rf & 1) {
ɵɵtemplate(0, null, 0, 0);
ɵɵtemplate(1, null, 0, 0);
ɵɵtemplate(2, null, 0, 0);
ɵɵtemplate(3, null, 0, 0);
ɵɵtemplate(4, null, 0, 0);
ɵɵtemplate(5, null, 0, 0);
ɵɵtemplate(6, null, 0, 0);
ɵɵtemplate(7, null, 0, 0);
ɵɵtemplate(8, null, 0, 0);
ɵɵtemplate(9, null, 0, 0);
}
}

const viewTNode = createTNode(null !, null, TNodeType.View, -1, null, null) as TViewNode;
const embeddedTView = createTView(-1, testTemplate, 10, 0, null, null, null, null, null);

// create view once so we don't profile first template pass
createAndRenderLView(null, embeddedTView, viewTNode);

// scenario to benchmark
const elementTextCreate = createBenchmark('ng_template');
const createTime = elementTextCreate('create');

console.profile('ng_template_create');
while (createTime()) {
createAndRenderLView(null, embeddedTView, viewTNode);
}
console.profileEnd();

// report results
elementTextCreate.report();

0 comments on commit df1bef3

Please sign in to comment.