Skip to content

Commit 6e9f485

Browse files
committed
perf: add button for profiling tree benchmark
1 parent 2e1feec commit 6e9f485

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

modules/benchmarks/src/tree/tree_benchmark.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ <h2>Angular2 tree benchmark</h2>
66
<p>
77
<button id="ng2DestroyDom">destroyDom</button>
88
<button id="ng2CreateDom">createDom</button>
9+
<button id="ng2UpdateDomProfile">profile updateDom</button>
10+
<button id="ng2CreateDomProfile">profile createDom</button>
911
</p>
1012

1113
<h2>Baseline tree benchmark</h2>
1214
<p>
1315
<button id="baselineDestroyDom">destroyDom</button>
1416
<button id="baselineCreateDom">createDom</button>
17+
<button id="baselineUpdateDomProfile">profile updateDom</button>
18+
<button id="baselineCreateDomProfile">profile createDom</button>
1519
</p>
1620

1721
<div>

modules/benchmarks/src/tree/tree_benchmark.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {TemplateLoader} from 'core/compiler/template_loader';
88
import {LifeCycle} from 'core/life_cycle/life_cycle';
99

1010
import {reflector} from 'reflection/reflection';
11-
import {DOM, document, Element} from 'facade/dom';
11+
import {DOM, document, window, Element} from 'facade/dom';
1212
import {isPresent} from 'facade/lang';
1313

1414
var MAX_DEPTH = 9;
@@ -135,6 +135,23 @@ export function main() {
135135
changeDetector.detectChanges();
136136
}
137137

138+
function profile(create, destroy, name) {
139+
return function(_) {
140+
window.console.profile(name);
141+
var duration = 0;
142+
var count = 0;
143+
while(duration < 5000) {
144+
var start = window.performance.now();
145+
create(_);
146+
duration += window.performance.now() - start;
147+
destroy(_);
148+
count++;
149+
}
150+
window.console.profileEnd(name);
151+
window.console.log(`Iterations: ${count}; time: ${duration / count} ms / iteration`);
152+
};
153+
}
154+
138155
function ng2CreateDom(_) {
139156
var values = count++ % 2 == 0 ?
140157
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '*'] :
@@ -144,12 +161,16 @@ export function main() {
144161
changeDetector.detectChanges();
145162
}
146163

164+
function noop() {}
165+
147166
function initNg2() {
148167
bootstrap(AppComponent).then((injector) => {
149168
changeDetector = injector.get(ChangeDetector);
150169
app = injector.get(AppComponent);
151170
DOM.on(DOM.querySelector(document, '#ng2DestroyDom'), 'click', ng2DestroyDom);
152171
DOM.on(DOM.querySelector(document, '#ng2CreateDom'), 'click', ng2CreateDom);
172+
DOM.on(DOM.querySelector(document, '#ng2UpdateDomProfile'), 'click', profile(ng2CreateDom, noop, 'ng2-update'));
173+
DOM.on(DOM.querySelector(document, '#ng2CreateDomProfile'), 'click', profile(ng2CreateDom, ng2DestroyDom, 'ng2-create'));
153174
});
154175
}
155176

@@ -170,6 +191,8 @@ export function main() {
170191
DOM.appendChild(DOM.querySelector(document, 'baseline'), baselineRootTreeComponent.element);
171192
DOM.on(DOM.querySelector(document, '#baselineDestroyDom'), 'click', baselineDestroyDom);
172193
DOM.on(DOM.querySelector(document, '#baselineCreateDom'), 'click', baselineCreateDom);
194+
DOM.on(DOM.querySelector(document, '#baselineUpdateDomProfile'), 'click', profile(baselineCreateDom, noop, 'baseline-update'));
195+
DOM.on(DOM.querySelector(document, '#baselineCreateDomProfile'), 'click', profile(baselineCreateDom, baselineDestroyDom, 'baseline-create'));
173196
}
174197

175198
initNg2();

modules/facade/src/dom.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ library angular.core.facade.dom;
33
import 'dart:html';
44
import 'dart:js' show JsObject;
55

6-
export 'dart:html' show DocumentFragment, Node, Element, TemplateElement, Text, document, location;
6+
export 'dart:html' show DocumentFragment, Node, Element, TemplateElement, Text, document, location, window;
77

88
// TODO(tbosch): Is there a builtin one? Why is Dart
99
// removing unknown elements by default?

modules/facade/src/dom.es6

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export var window = frames.window;
12
export var DocumentFragment = window.DocumentFragment;
23
export var Node = window.Node;
34
export var NodeList = window.NodeList;

0 commit comments

Comments
 (0)