2015-11-19 15:09:34 -08:00
|
|
|
import {DOM} from 'angular2/src/platform/dom/dom_adapter';
|
2015-11-06 17:34:07 -08:00
|
|
|
import {window, document, gc} from 'angular2/src/facade/browser';
|
2015-05-29 21:40:15 -07:00
|
|
|
import {
|
|
|
|
getIntParameter,
|
|
|
|
getStringParameter,
|
2015-05-30 08:17:27 -07:00
|
|
|
bindAction,
|
|
|
|
windowProfile,
|
|
|
|
windowProfileEnd
|
2015-10-13 00:29:13 -07:00
|
|
|
} from 'angular2/src/testing/benchmark_util';
|
2015-09-03 22:01:36 -07:00
|
|
|
import {bootstrap} from 'angular2/bootstrap';
|
2015-11-18 15:55:43 -08:00
|
|
|
import {Component, Directive, View, bind, provide} from 'angular2/core';
|
|
|
|
import {NgFor, NgSwitch, NgSwitchWhen, NgSwitchDefault} from 'angular2/common';
|
2015-10-28 10:34:13 -07:00
|
|
|
import {ApplicationRef} from 'angular2/src/core/application_ref';
|
2015-11-17 15:24:36 -08:00
|
|
|
import {BrowserDomAdapter} from 'angular2/src/platform/browser/browser_adapter';
|
2015-10-02 07:37:23 -07:00
|
|
|
import {APP_VIEW_POOL_CAPACITY} from 'angular2/src/core/linker/view_pool';
|
2015-02-03 15:29:05 -08:00
|
|
|
|
2015-11-06 17:34:07 -08:00
|
|
|
import {ListWrapper} from 'angular2/src/facade/collection';
|
2015-02-03 15:29:05 -08:00
|
|
|
|
2015-08-20 14:28:25 -07:00
|
|
|
import {Inject} from 'angular2/src/core/di/decorators';
|
|
|
|
import {reflector} from 'angular2/src/core/reflection/reflection';
|
2015-04-09 17:53:36 -07:00
|
|
|
|
|
|
|
export const BENCHMARK_TYPE = 'LargetableComponent.benchmarkType';
|
|
|
|
export const LARGETABLE_ROWS = 'LargetableComponent.rows';
|
|
|
|
export const LARGETABLE_COLS = 'LargetableComponent.cols';
|
2015-04-16 16:29:46 -07:00
|
|
|
|
2015-04-09 17:53:36 -07:00
|
|
|
function _createBindings() {
|
2015-06-09 15:00:49 -07:00
|
|
|
var viewCacheCapacity = getStringParameter('viewcache') == 'true' ? 10000 : 1;
|
2015-04-09 17:53:36 -07:00
|
|
|
return [
|
2015-10-12 11:30:34 -07:00
|
|
|
provide(BENCHMARK_TYPE, {useValue: getStringParameter('benchmarkType')}),
|
|
|
|
provide(LARGETABLE_ROWS, {useValue: getIntParameter('rows')}),
|
|
|
|
provide(LARGETABLE_COLS, {useValue: getIntParameter('columns')}),
|
|
|
|
provide(APP_VIEW_POOL_CAPACITY, {useValue: viewCacheCapacity})
|
2015-04-09 17:53:36 -07:00
|
|
|
];
|
|
|
|
}
|
2015-04-07 20:54:20 -07:00
|
|
|
|
2015-02-03 15:29:05 -08:00
|
|
|
var BASELINE_LARGETABLE_TEMPLATE;
|
|
|
|
|
|
|
|
function setupReflector() {
|
2015-04-09 17:53:36 -07:00
|
|
|
// TODO(kegluneq): Generate these.
|
2015-02-03 15:29:05 -08:00
|
|
|
reflector.registerGetters({
|
2015-04-09 17:53:36 -07:00
|
|
|
'benchmarktype': (o) => o.benchmarktype,
|
|
|
|
'switch': (o) => null,
|
|
|
|
'switchWhen': (o) => o.switchWhen
|
2015-02-03 15:29:05 -08:00
|
|
|
});
|
|
|
|
reflector.registerSetters({
|
2015-04-09 17:53:36 -07:00
|
|
|
'benchmarktype': (o, v) => o.benchmarktype = v,
|
|
|
|
'switch': (o, v) => null,
|
|
|
|
'switchWhen': (o, v) => o.switchWhen = v
|
2015-02-03 15:29:05 -08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function main() {
|
|
|
|
BrowserDomAdapter.makeCurrent();
|
|
|
|
var totalRows = getIntParameter('rows');
|
|
|
|
var totalColumns = getIntParameter('columns');
|
2015-05-29 21:40:15 -07:00
|
|
|
BASELINE_LARGETABLE_TEMPLATE = DOM.createTemplate('<table></table>');
|
2015-02-03 15:29:05 -08:00
|
|
|
|
|
|
|
var app;
|
2015-10-28 10:34:13 -07:00
|
|
|
var appRef;
|
2015-02-03 15:29:05 -08:00
|
|
|
var baselineRootLargetableComponent;
|
|
|
|
|
|
|
|
function ng2DestroyDom() {
|
|
|
|
// TODO: We need an initial value as otherwise the getter for data.value will fail
|
|
|
|
// --> this should be already caught in change detection!
|
|
|
|
app.data = null;
|
|
|
|
app.benchmarkType = 'none';
|
2015-10-28 10:34:13 -07:00
|
|
|
appRef.tick();
|
2015-02-03 15:29:05 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
function profile(create, destroy, name) {
|
|
|
|
return function() {
|
2015-05-30 08:17:27 -07:00
|
|
|
windowProfile(name + ' w GC');
|
2015-02-03 15:29:05 -08:00
|
|
|
var duration = 0;
|
|
|
|
var count = 0;
|
2015-05-29 21:40:15 -07:00
|
|
|
while (count++ < 150) {
|
2015-02-03 15:29:05 -08:00
|
|
|
gc();
|
|
|
|
var start = window.performance.now();
|
|
|
|
create();
|
|
|
|
duration += window.performance.now() - start;
|
|
|
|
destroy();
|
|
|
|
}
|
2015-05-30 08:17:27 -07:00
|
|
|
windowProfileEnd(name + ' w GC');
|
2015-02-03 15:29:05 -08:00
|
|
|
window.console.log(`Iterations: ${count}; time: ${duration / count} ms / iteration`);
|
|
|
|
|
2015-05-30 08:17:27 -07:00
|
|
|
windowProfile(name + ' w/o GC');
|
2015-02-03 15:29:05 -08:00
|
|
|
duration = 0;
|
|
|
|
count = 0;
|
2015-05-29 21:40:15 -07:00
|
|
|
while (count++ < 150) {
|
2015-02-03 15:29:05 -08:00
|
|
|
var start = window.performance.now();
|
|
|
|
create();
|
|
|
|
duration += window.performance.now() - start;
|
|
|
|
destroy();
|
|
|
|
}
|
2015-05-30 08:17:27 -07:00
|
|
|
windowProfileEnd(name + ' w/o GC');
|
2015-02-03 15:29:05 -08:00
|
|
|
window.console.log(`Iterations: ${count}; time: ${duration / count} ms / iteration`);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function ng2CreateDom() {
|
|
|
|
var data = ListWrapper.createFixedSize(totalRows);
|
|
|
|
|
2015-05-29 21:40:15 -07:00
|
|
|
for (var i = 0; i < totalRows; i++) {
|
2015-02-03 15:29:05 -08:00
|
|
|
data[i] = ListWrapper.createFixedSize(totalColumns);
|
2015-05-29 21:40:15 -07:00
|
|
|
for (var j = 0; j < totalColumns; j++) {
|
|
|
|
data[i][j] = new CellData(i, j);
|
2015-02-03 15:29:05 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
app.data = data;
|
|
|
|
app.benchmarkType = getStringParameter('benchmarkType');
|
2015-10-28 10:34:13 -07:00
|
|
|
appRef.tick();
|
2015-02-03 15:29:05 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
function noop() {}
|
|
|
|
|
|
|
|
function initNg2() {
|
2015-05-29 21:40:15 -07:00
|
|
|
bootstrap(AppComponent, _createBindings())
|
|
|
|
.then((ref) => {
|
2015-10-08 09:57:10 -07:00
|
|
|
var injector = ref.injector;
|
2015-06-26 15:59:18 -07:00
|
|
|
app = ref.hostComponent;
|
2015-10-28 10:34:13 -07:00
|
|
|
appRef = injector.get(ApplicationRef);
|
2015-05-29 21:40:15 -07:00
|
|
|
bindAction('#ng2DestroyDom', ng2DestroyDom);
|
|
|
|
bindAction('#ng2CreateDom', ng2CreateDom);
|
|
|
|
bindAction('#ng2UpdateDomProfile', profile(ng2CreateDom, noop, 'ng2-update'));
|
|
|
|
bindAction('#ng2CreateDomProfile', profile(ng2CreateDom, ng2DestroyDom, 'ng2-create'));
|
|
|
|
});
|
2015-07-22 10:18:04 -07:00
|
|
|
setupReflector();
|
2015-02-03 15:29:05 -08:00
|
|
|
}
|
|
|
|
|
2015-05-29 21:40:15 -07:00
|
|
|
function baselineDestroyDom() { baselineRootLargetableComponent.update(buildTable(0, 0)); }
|
2015-02-03 15:29:05 -08:00
|
|
|
|
|
|
|
function baselineCreateDom() {
|
|
|
|
baselineRootLargetableComponent.update(buildTable(totalRows, totalColumns));
|
|
|
|
}
|
|
|
|
|
|
|
|
function initBaseline() {
|
|
|
|
baselineRootLargetableComponent = new BaseLineLargetableComponent(
|
|
|
|
DOM.querySelector(document, 'baseline'), getStringParameter('benchmarkType'),
|
|
|
|
getIntParameter('rows'), getIntParameter('columns'));
|
|
|
|
|
|
|
|
bindAction('#baselineDestroyDom', baselineDestroyDom);
|
|
|
|
bindAction('#baselineCreateDom', baselineCreateDom);
|
|
|
|
|
|
|
|
bindAction('#baselineUpdateDomProfile', profile(baselineCreateDom, noop, 'baseline-update'));
|
2015-05-29 21:40:15 -07:00
|
|
|
bindAction('#baselineCreateDomProfile',
|
|
|
|
profile(baselineCreateDom, baselineDestroyDom, 'baseline-create'));
|
2015-02-03 15:29:05 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
initNg2();
|
|
|
|
initBaseline();
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildTable(rows, columns) {
|
|
|
|
var tbody = DOM.createElement('tbody');
|
|
|
|
var template = DOM.createElement('span');
|
2015-05-29 21:40:15 -07:00
|
|
|
var i, j, row, cell;
|
2015-02-03 15:29:05 -08:00
|
|
|
DOM.appendChild(template, DOM.createElement('span'));
|
|
|
|
DOM.appendChild(template, DOM.createTextNode(':'));
|
|
|
|
DOM.appendChild(template, DOM.createElement('span'));
|
|
|
|
DOM.appendChild(template, DOM.createTextNode('|'));
|
|
|
|
|
|
|
|
for (i = 0; i < rows; i++) {
|
|
|
|
row = DOM.createElement('div');
|
|
|
|
DOM.appendChild(tbody, row);
|
|
|
|
for (j = 0; j < columns; j++) {
|
|
|
|
cell = DOM.clone(template);
|
|
|
|
DOM.appendChild(row, cell);
|
|
|
|
DOM.setText(cell.childNodes[0], i.toString());
|
|
|
|
DOM.setText(cell.childNodes[2], j.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return tbody;
|
|
|
|
}
|
|
|
|
|
|
|
|
class BaseLineLargetableComponent {
|
|
|
|
element;
|
|
|
|
table;
|
2015-05-29 21:40:15 -07:00
|
|
|
benchmarkType: string;
|
|
|
|
rows: number;
|
|
|
|
columns: number;
|
|
|
|
constructor(element, benchmarkType, rows: number, columns: number) {
|
2015-02-03 15:29:05 -08:00
|
|
|
this.element = element;
|
|
|
|
this.benchmarkType = benchmarkType;
|
|
|
|
this.rows = rows;
|
|
|
|
this.columns = columns;
|
|
|
|
this.table = DOM.clone(BASELINE_LARGETABLE_TEMPLATE.content.firstChild);
|
2015-05-30 08:17:27 -07:00
|
|
|
var shadowRoot = DOM.createShadowRoot(this.element);
|
|
|
|
DOM.appendChild(shadowRoot, this.table);
|
2015-02-03 15:29:05 -08:00
|
|
|
}
|
|
|
|
update(tbody) {
|
|
|
|
var oldBody = DOM.querySelector(this.table, 'tbody');
|
|
|
|
if (oldBody != null) {
|
|
|
|
DOM.replaceChild(this.table, tbody, oldBody);
|
|
|
|
} else {
|
|
|
|
DOM.appendChild(this.table, tbody);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class CellData {
|
2015-05-29 21:40:15 -07:00
|
|
|
i: number;
|
|
|
|
j: number;
|
|
|
|
constructor(i, j) {
|
2015-02-03 15:29:05 -08:00
|
|
|
this.i = i;
|
|
|
|
this.j = j;
|
|
|
|
}
|
|
|
|
|
2015-05-29 21:40:15 -07:00
|
|
|
jFn() { return this.j; }
|
2015-02-03 15:29:05 -08:00
|
|
|
|
2015-05-29 21:40:15 -07:00
|
|
|
iFn() { return this.i; }
|
2015-02-03 15:29:05 -08:00
|
|
|
}
|
|
|
|
|
2015-09-30 20:59:23 -07:00
|
|
|
@Component({selector: 'largetable', inputs: ['data', 'benchmarkType']})
|
2015-04-09 17:53:36 -07:00
|
|
|
@View({
|
2015-05-11 17:04:55 -07:00
|
|
|
directives: [NgFor, NgSwitch, NgSwitchWhen, NgSwitchDefault],
|
2015-04-09 17:53:36 -07:00
|
|
|
template: `
|
2015-05-11 16:07:23 -07:00
|
|
|
<table [ng-switch]="benchmarkType">
|
2015-05-30 08:17:27 -07:00
|
|
|
<tbody template="ng-switch-when 'interpolation'">
|
|
|
|
<tr template="ng-for #row of data">
|
|
|
|
<td template="ng-for #column of row">
|
2015-04-09 17:53:36 -07:00
|
|
|
{{column.i}}:{{column.j}}|
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
2015-05-30 08:17:27 -07:00
|
|
|
<tbody template="ng-switch-when 'interpolationAttr'">
|
|
|
|
<tr template="ng-for #row of data">
|
2015-06-17 16:05:35 +02:00
|
|
|
<td template="ng-for #column of row" attr.i="{{column.i}}" attr.j="{{column.j}}">
|
2015-04-09 17:53:36 -07:00
|
|
|
i,j attrs
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
2015-05-30 08:17:27 -07:00
|
|
|
<tbody template="ng-switch-when 'interpolationFn'">
|
|
|
|
<tr template="ng-for #row of data">
|
|
|
|
<td template="ng-for #column of row">
|
2015-04-09 17:53:36 -07:00
|
|
|
{{column.iFn()}}:{{column.jFn()}}|
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
2015-05-30 08:17:27 -07:00
|
|
|
<tbody template="ng-switch-default">
|
2015-04-09 17:53:36 -07:00
|
|
|
<tr>
|
|
|
|
<td>
|
|
|
|
<em>{{benchmarkType}} not yet implemented</em>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>`
|
|
|
|
})
|
2015-02-03 15:29:05 -08:00
|
|
|
class LargetableComponent {
|
|
|
|
data;
|
2015-05-29 21:40:15 -07:00
|
|
|
benchmarkType: string;
|
|
|
|
rows: number;
|
|
|
|
columns: number;
|
2015-05-30 08:17:27 -07:00
|
|
|
constructor(@Inject(BENCHMARK_TYPE) benchmarkType, @Inject(LARGETABLE_ROWS) rows,
|
|
|
|
@Inject(LARGETABLE_COLS) columns) {
|
2015-02-03 15:29:05 -08:00
|
|
|
this.benchmarkType = benchmarkType;
|
|
|
|
this.rows = rows;
|
|
|
|
this.columns = columns;
|
|
|
|
}
|
|
|
|
}
|
2015-05-30 08:17:27 -07:00
|
|
|
|
|
|
|
@Component({selector: 'app'})
|
|
|
|
@View({
|
|
|
|
directives: [LargetableComponent],
|
2015-06-17 16:05:35 +02:00
|
|
|
template: `<largetable [data]='data' [benchmark-type]='benchmarkType'></largetable>`
|
2015-05-30 08:17:27 -07:00
|
|
|
})
|
|
|
|
class AppComponent {
|
|
|
|
data;
|
|
|
|
benchmarkType: string;
|
|
|
|
}
|