chore: format benchmarks

closes #11112
This commit is contained in:
Tobias Bosch 2016-08-26 15:44:05 -07:00 committed by Victor Berchet
parent 61002733bc
commit c377e80670
25 changed files with 248 additions and 345 deletions

View File

@ -13,15 +13,14 @@ describe('ng2 naive infinite scroll benchmark', function() {
url: URL, url: URL,
id: 'ng2.naive_infinite_scroll', id: 'ng2.naive_infinite_scroll',
work: function() { work: function() {
browser.wait(protractor.until.elementLocated(protractor.By.css('body /deep/ #scrollDiv')), browser.wait(
5000); protractor.until.elementLocated(protractor.By.css('body /deep/ #scrollDiv')), 5000);
$('#reset-btn').click(); $('#reset-btn').click();
$('#run-btn').click(); $('#run-btn').click();
browser.wait(protractor.until.elementLocated(protractor.By.css('#done')), 10000); browser.wait(protractor.until.elementLocated(protractor.By.css('#done')), 10000);
}, },
params: [ params: [
{name: 'appSize', value: appSize}, {name: 'appSize', value: appSize}, {name: 'iterationCount', value: 20, scale: 'linear'},
{name: 'iterationCount', value: 20, scale: 'linear'},
{name: 'scrollIncrement', value: 40} {name: 'scrollIncrement', value: 40}
] ]
}).then(done, done.fail); }).then(done, done.fail);

View File

@ -16,7 +16,8 @@ describe('ng2 naive infinite scroll benchmark', function() {
var stageButtons = `${ allScrollItems } .row stage-buttons button`; var stageButtons = `${ allScrollItems } .row stage-buttons button`;
var count = function(selector) { var count = function(selector) {
return browser.executeScript(`return ` + return browser.executeScript(
`return ` +
`document.querySelectorAll("${ selector }").length;`); `document.querySelectorAll("${ selector }").length;`);
}; };
@ -25,7 +26,8 @@ describe('ng2 naive infinite scroll benchmark', function() {
}; };
var firstTextOf = function(selector) { var firstTextOf = function(selector) {
return browser.executeScript(`return ` + return browser.executeScript(
`return ` +
`document.querySelector("${ selector }").innerText;`); `document.querySelector("${ selector }").innerText;`);
}; };
@ -36,18 +38,17 @@ describe('ng2 naive infinite scroll benchmark', function() {
count(cells).then(function(c) { expect(c).toEqual(expectedRowCount * expectedCellsPerRow); }); count(cells).then(function(c) { expect(c).toEqual(expectedRowCount * expectedCellsPerRow); });
// Click on first enabled button and verify stage changes // Click on first enabled button and verify stage changes
firstTextOf(`${ stageButtons }:enabled`) firstTextOf(`${ stageButtons }:enabled`).then(function(text) {
.then(function(text) {
expect(text).toEqual('Pitched'); expect(text).toEqual('Pitched');
clickFirstOf(`${ stageButtons }:enabled`) clickFirstOf(`${ stageButtons }:enabled`).then(function() {
.then(function() { firstTextOf(`${ stageButtons }:enabled`).then(function(text) {
firstTextOf(`${ stageButtons }:enabled`) expect(text).toEqual('Won');
.then(function(text) { expect(text).toEqual('Won'); }) })
}); });
}); });
$("#reset-btn").click(); $('#reset-btn').click();
$("#run-btn").click(); $('#run-btn').click();
browser.wait(() => { browser.wait(() => {
return $('#done').getText().then(function() { return true; }, function() { return false; }); return $('#done').getText().then(function() { return true; }, function() { return false; });
}, 10000); }, 10000);

View File

@ -9,15 +9,15 @@ describe('ng2 largetable benchmark', function() {
it('should log the load time', function(done) { it('should log the load time', function(done) {
runner.sample({ runner
.sample({
id: 'loadTime', id: 'loadTime',
prepare: null, prepare: null,
microMetrics: null, microMetrics: null,
userMetrics: userMetrics:
{loadTime: 'The time in milliseconds to bootstrap', someConstant: 'Some constant'}, {loadTime: 'The time in milliseconds to bootstrap', someConstant: 'Some constant'},
bindings: [ bindings: [
benchpress.bind(benchpress.SizeValidator.SAMPLE_SIZE) benchpress.bind(benchpress.SizeValidator.SAMPLE_SIZE).toValue(2),
.toValue(2),
benchpress.bind(benchpress.RegressionSlopeValidator.SAMPLE_SIZE).toValue(2), benchpress.bind(benchpress.RegressionSlopeValidator.SAMPLE_SIZE).toValue(2),
benchpress.bind(benchpress.RegressionSlopeValidator.METRIC).toValue('someConstant') benchpress.bind(benchpress.RegressionSlopeValidator.METRIC).toValue('someConstant')
], ],

View File

@ -93,9 +93,9 @@
while (match = regex.exec(search)) { while (match = regex.exec(search)) {
var name = match[1]; var name = match[1];
var value = match[2]; var value = match[2];
var els = document.querySelectorAll('input[name="'+name+'"]'); var els = document.querySelectorAll('input[name="' + name + '"]');
var el: any; var el: any;
for (var i=0; i<els.length; i++) { for (var i = 0; i < els.length; i++) {
el = els[i]; el = els[i];
if (el.type === 'radio' || el.type === 'checkbox') { if (el.type === 'radio' || el.type === 'checkbox') {
el.checked = el.value === value; el.checked = el.value === value;

View File

@ -1,16 +1,11 @@
import {PromiseWrapper} from '@angular/facade/src/async';
import {ListWrapper, Map, MapWrapper} from '@angular/facade/src/collection';
import {DateWrapper, Type, isPresent, print} from '@angular/facade/src/lang';
import {bootstrap} from '@angular/platform-browser'; import {bootstrap} from '@angular/platform-browser';
import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter'; import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter';
import {DOM} from '@angular/platform-browser/src/dom/dom_adapter'; import {DOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {PromiseWrapper} from '@angular/facade/src/async';
import {ListWrapper, Map, MapWrapper} from '@angular/facade/src/collection';
import {DateWrapper, Type, print, isPresent} from '@angular/facade/src/lang';
import { import {ComponentResolver, Component, Directive, ViewContainerRef,} from '@angular/core';
ComponentResolver,
Component,
Directive,
ViewContainerRef,
} from '@angular/core';
import {ViewMetadata} from '@angular/core/src/metadata/view'; import {ViewMetadata} from '@angular/core/src/metadata/view';
@ -23,26 +18,27 @@ function _createBindings(): any[] {
return [ return [
{ {
provide: DirectiveResolver, provide: DirectiveResolver,
useFactory: () => new MultiplyDirectiveResolver( useFactory:
multiplyTemplatesBy, () => new MultiplyDirectiveResolver(
[BenchmarkComponentNoBindings, BenchmarkComponentWithBindings]), multiplyTemplatesBy, [BenchmarkComponentNoBindings, BenchmarkComponentWithBindings]),
deps: [] deps: []
}, },
// Use interpretative mode as Dart does not support JIT and // Use interpretative mode as Dart does not support JIT and
// we want to be able to compare the numbers between JS and Dart // we want to be able to compare the numbers between JS and Dart
{provide: CompilerConfig, useValue: new CompilerConfig({genDebugInfo: false, useJit: false, logBindingUpdate: false})} {
provide: CompilerConfig,
useValue: new CompilerConfig({genDebugInfo: false, useJit: false, logBindingUpdate: false})
}
]; ];
} }
export function main() { export function main() {
BrowserDomAdapter.makeCurrent(); BrowserDomAdapter.makeCurrent();
bootstrap(CompilerAppComponent, _createBindings()) bootstrap(CompilerAppComponent, _createBindings()).then((ref) => {
.then((ref) => {
var app = ref.instance; var app = ref.instance;
bindAction('#compileNoBindings', bindAction('#compileNoBindings', measureWrapper(() => app.compileNoBindings(), 'No Bindings'));
measureWrapper(() => app.compileNoBindings(), 'No Bindings')); bindAction(
bindAction('#compileWithBindings', '#compileWithBindings', measureWrapper(() => app.compileWithBindings(), 'With Bindings'));
measureWrapper(() => app.compileWithBindings(), 'With Bindings'));
}); });
} }

View File

@ -1,8 +1,8 @@
import {SelectorMatcher} from '@angular/compiler/src/selector'; import {SelectorMatcher} from '@angular/compiler/src/selector';
import {CssSelector} from '@angular/compiler/src/selector'; import {CssSelector} from '@angular/compiler/src/selector';
import {StringWrapper, Math} from '@angular/facade/lang'; import {Math, StringWrapper} from '@angular/facade/lang';
import {getIntParameter, bindAction} from '@angular/testing/src/benchmark_util';
import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter'; import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter';
import {bindAction, getIntParameter} from '@angular/testing/src/benchmark_util';
export function main() { export function main() {
BrowserDomAdapter.makeCurrent(); BrowserDomAdapter.makeCurrent();

View File

@ -1,11 +1,11 @@
import {bootstrap} from '@angular/platform-browser'; import {NgFor, NgIf} from '@angular/common';
import {Component, Directive, DynamicComponentLoader, ViewContainerRef} from '@angular/core'; import {Component, Directive, DynamicComponentLoader, ViewContainerRef} from '@angular/core';
import {NgIf, NgFor} from '@angular/common';
import {ApplicationRef} from '@angular/core/src/application_ref'; import {ApplicationRef} from '@angular/core/src/application_ref';
import {ListWrapper} from '@angular/facade/src/lang'; import {ListWrapper} from '@angular/facade/src/lang';
import {getIntParameter, bindAction} from '@angular/testing/src/benchmark_util'; import {bootstrap} from '@angular/platform-browser';
import {BrowserModule} from '@angular/platform-browser'; import {BrowserModule} from '@angular/platform-browser';
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {bindAction, getIntParameter} from '@angular/testing/src/benchmark_util';
var testList = null; var testList = null;
@ -13,8 +13,7 @@ export function main() {
var size = getIntParameter('size'); var size = getIntParameter('size');
testList = ListWrapper.createFixedSize(size); testList = ListWrapper.createFixedSize(size);
platformBrowserDynamic().bootstrapModule(AppModule) platformBrowserDynamic().bootstrapModule(AppModule).then((ref) => {
.then((ref) => {
var injector = ref.injector; var injector = ref.injector;
var app: AppComponent = ref.instance; var app: AppComponent = ref.instance;
var appRef = injector.get(ApplicationRef); var appRef = injector.get(ApplicationRef);
@ -110,9 +109,6 @@ class AppComponent {
@NgModule({ @NgModule({imports: [BrowserModule], bootstrap: [AppComponent]})
imports: [BrowserModule],
bootstrap: [AppComponent]
})
class AppModule { class AppModule {
} }

View File

@ -1,8 +1,8 @@
import {Injectable, ReflectiveInjector, ReflectiveKey} from '@angular/core'; import {Injectable, ReflectiveInjector, ReflectiveKey} from '@angular/core';
import {reflector} from '@angular/core/src/reflection/reflection'; import {reflector} from '@angular/core/src/reflection/reflection';
import {ReflectionCapabilities} from '@angular/core/src/reflection/reflection_capabilities'; import {ReflectionCapabilities} from '@angular/core/src/reflection/reflection_capabilities';
import {getIntParameter, bindAction, microBenchmark} from '@angular/testing/src/benchmark_util';
import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter'; import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter';
import {bindAction, getIntParameter, microBenchmark} from '@angular/testing/src/benchmark_util';
var count = 0; var count = 0;
@ -81,7 +81,8 @@ export function main() {
bindAction('#getChild', () => microBenchmark('injectAvg', iterations, getChild)); bindAction('#getChild', () => microBenchmark('injectAvg', iterations, getChild));
bindAction('#instantiate', () => microBenchmark('injectAvg', iterations, instantiate)); bindAction('#instantiate', () => microBenchmark('injectAvg', iterations, instantiate));
bindAction('#createVariety', () => microBenchmark('injectAvg', iterations, createVariety)); bindAction('#createVariety', () => microBenchmark('injectAvg', iterations, createVariety));
bindAction('#createVarietyResolved', bindAction(
'#createVarietyResolved',
() => microBenchmark('injectAvg', iterations, createVarietyResolved)); () => microBenchmark('injectAvg', iterations, createVarietyResolved));
} }

View File

@ -1,22 +1,14 @@
import {DOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {window, document, gc} from '@angular/facade/src/browser';
import {
getIntParameter,
getStringParameter,
bindAction,
windowProfile,
windowProfileEnd
} from '@angular/testing/src/benchmark_util';
import {bootstrap} from '@angular/platform-browser';
import {Component} from '@angular/core';
import {NgFor, NgSwitch, NgSwitchCase, NgSwitchDefault} from '@angular/common'; import {NgFor, NgSwitch, NgSwitchCase, NgSwitchDefault} from '@angular/common';
import {Component} from '@angular/core';
import {ApplicationRef} from '@angular/core/src/application_ref'; import {ApplicationRef} from '@angular/core/src/application_ref';
import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter';
import {ListWrapper} from '@angular/facade/src/collection';
import {Inject} from '@angular/core/src/di/decorators'; import {Inject} from '@angular/core/src/di/decorators';
import {reflector} from '@angular/core/src/reflection/reflection'; import {reflector} from '@angular/core/src/reflection/reflection';
import {document, gc, window} from '@angular/facade/src/browser';
import {ListWrapper} from '@angular/facade/src/collection';
import {bootstrap} from '@angular/platform-browser';
import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter';
import {DOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {bindAction, getIntParameter, getStringParameter, windowProfile, windowProfileEnd} from '@angular/testing/src/benchmark_util';
export const BENCHMARK_TYPE = 'LargetableComponent.benchmarkType'; export const BENCHMARK_TYPE = 'LargetableComponent.benchmarkType';
export const LARGETABLE_ROWS = 'LargetableComponent.rows'; export const LARGETABLE_ROWS = 'LargetableComponent.rows';
@ -110,8 +102,7 @@ export function main() {
function noop() {} function noop() {}
function initNg2() { function initNg2() {
bootstrap(AppComponent, _createBindings()) bootstrap(AppComponent, _createBindings()).then((ref) => {
.then((ref) => {
var injector = ref.injector; var injector = ref.injector;
app = ref.instance; app = ref.instance;
appRef = injector.get(ApplicationRef); appRef = injector.get(ApplicationRef);
@ -138,7 +129,8 @@ export function main() {
bindAction('#baselineCreateDom', baselineCreateDom); bindAction('#baselineCreateDom', baselineCreateDom);
bindAction('#baselineUpdateDomProfile', profile(baselineCreateDom, noop, 'baseline-update')); bindAction('#baselineUpdateDomProfile', profile(baselineCreateDom, noop, 'baseline-update'));
bindAction('#baselineCreateDomProfile', bindAction(
'#baselineCreateDomProfile',
profile(baselineCreateDom, baselineDestroyDom, 'baseline-create')); profile(baselineCreateDom, baselineDestroyDom, 'baseline-create'));
} }
@ -248,7 +240,8 @@ class LargetableComponent {
benchmarkType: string; benchmarkType: string;
rows: number; rows: number;
columns: number; columns: number;
constructor(@Inject(BENCHMARK_TYPE) benchmarkType, @Inject(LARGETABLE_ROWS) rows, constructor(
@Inject(BENCHMARK_TYPE) benchmarkType, @Inject(LARGETABLE_ROWS) rows,
@Inject(LARGETABLE_COLS) columns) { @Inject(LARGETABLE_COLS) columns) {
this.benchmarkType = benchmarkType; this.benchmarkType = benchmarkType;
this.rows = rows; this.rows = rows;

View File

@ -1,12 +1,12 @@
import {isPresent} from '@angular/facade/src/lang'; import {NgFor, NgIf} from '@angular/common';
import {getIntParameter, bindAction} from '@angular/testing/src/benchmark_util';
import {TimerWrapper} from '@angular/facade/src/async';
import {ScrollAreaComponent} from './scroll_area';
import {NgIf, NgFor} from '@angular/common';
import {DOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {document} from '@angular/facade/src/browser';
import {Component, Directive} from '@angular/core'; import {Component, Directive} from '@angular/core';
import {TimerWrapper} from '@angular/facade/src/async';
import {document} from '@angular/facade/src/browser';
import {isPresent} from '@angular/facade/src/lang';
import {DOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {bindAction, getIntParameter} from '@angular/testing/src/benchmark_util';
import {ScrollAreaComponent} from './scroll_area';
@Component({ @Component({

View File

@ -1,8 +1,8 @@
import {ListWrapper, Map} from '@angular/facade/src/collection';
import {Company, Opportunity, Offering, Account, CustomDate, STATUS_LIST} from './common';
import {NgFor} from '@angular/common'; import {NgFor} from '@angular/common';
import {Component, Directive} from '@angular/core'; import {Component, Directive} from '@angular/core';
import {ListWrapper, Map} from '@angular/facade/src/collection';
import {Account, Company, CustomDate, Offering, Opportunity, STATUS_LIST} from './common';
export class HasStyle { export class HasStyle {
cellWidth: number; cellWidth: number;

View File

@ -1,6 +1,6 @@
import {Math} from '@angular/facade/src/math';
import {StringWrapper} from '@angular/facade/src/lang';
import {ListWrapper, Map, MapWrapper} from '@angular/facade/src/collection'; import {ListWrapper, Map, MapWrapper} from '@angular/facade/src/collection';
import {StringWrapper} from '@angular/facade/src/lang';
import {Math} from '@angular/facade/src/math';
export var ITEMS = 1000; export var ITEMS = 1000;
export var ITEM_HEIGHT = 40; export var ITEM_HEIGHT = 40;
@ -21,9 +21,8 @@ export var DUE_DATE_WIDTH = 100;
export var END_DATE_WIDTH = 100; export var END_DATE_WIDTH = 100;
export var AAT_STATUS_WIDTH = 100; export var AAT_STATUS_WIDTH = 100;
export var ROW_WIDTH = COMPANY_NAME_WIDTH + OPPORTUNITY_NAME_WIDTH + OFFERING_NAME_WIDTH + export var ROW_WIDTH = COMPANY_NAME_WIDTH + OPPORTUNITY_NAME_WIDTH + OFFERING_NAME_WIDTH +
ACCOUNT_CELL_WIDTH + BASE_POINTS_WIDTH + KICKER_POINTS_WIDTH + ACCOUNT_CELL_WIDTH + BASE_POINTS_WIDTH + KICKER_POINTS_WIDTH + STAGE_BUTTONS_WIDTH +
STAGE_BUTTONS_WIDTH + BUNDLES_WIDTH + DUE_DATE_WIDTH + END_DATE_WIDTH + BUNDLES_WIDTH + DUE_DATE_WIDTH + END_DATE_WIDTH + AAT_STATUS_WIDTH;
AAT_STATUS_WIDTH;
export var STATUS_LIST = ['Planned', 'Pitched', 'Won', 'Lost']; export var STATUS_LIST = ['Planned', 'Pitched', 'Won', 'Lost'];

View File

@ -1,15 +1,10 @@
import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser'; import {BrowserModule} from '@angular/platform-browser';
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {
NgModule
} from '@angular/core';
import {App} from './app'; import {App} from './app';
@NgModule({ @NgModule({imports: [BrowserModule], bootstrap: [App]})
imports: [BrowserModule],
bootstrap: [App]
})
class AppModule { class AppModule {
} }

View File

@ -1,13 +1,6 @@
import {StringWrapper} from '@angular/facade/src/lang'; import {StringWrapper} from '@angular/facade/src/lang';
import {
CustomDate, import {AAT_STATUS_LIST, Account, Company, CustomDate, Offering, Opportunity, STATUS_LIST} from './common';
Offering,
Company,
Opportunity,
Account,
STATUS_LIST,
AAT_STATUS_LIST
} from './common';
export function generateOfferings(count: number): Offering[] { export function generateOfferings(count: number): Offering[] {
var res = []; var res = [];
@ -52,18 +45,7 @@ export function generateAccount(seed: number): Account {
} }
var names = [ var names = [
'Foo', 'Foo', 'Bar', 'Baz', 'Qux', 'Quux', 'Garply', 'Waldo', 'Fred', 'Plugh', 'Xyzzy', 'Thud', 'Cruft',
'Bar',
'Baz',
'Qux',
'Quux',
'Garply',
'Waldo',
'Fred',
'Plugh',
'Xyzzy',
'Thud',
'Cruft',
'Stuff' 'Stuff'
]; ];

View File

@ -1,20 +1,11 @@
import {NgFor} from '@angular/common';
import {Component, Directive} from '@angular/core';
import {ListWrapper} from '@angular/facade/src/collection'; import {ListWrapper} from '@angular/facade/src/collection';
import {Math} from '@angular/facade/src/math'; import {Math} from '@angular/facade/src/math';
import {Component, Directive} from '@angular/core'; import {HEIGHT, ITEMS, ITEM_HEIGHT, Offering, ROW_WIDTH, VIEW_PORT_HEIGHT, VISIBLE_ITEMS} from './common';
import {
Offering,
ITEMS,
ITEM_HEIGHT,
VISIBLE_ITEMS,
VIEW_PORT_HEIGHT,
ROW_WIDTH,
HEIGHT
} from './common';
import {generateOfferings} from './random_data'; import {generateOfferings} from './random_data';
import {ScrollItemComponent} from './scroll_item'; import {ScrollItemComponent} from './scroll_item';
import {NgFor} from '@angular/common';
@Component({ @Component({
selector: 'scroll-area', selector: 'scroll-area',

View File

@ -1,40 +1,14 @@
import {
CompanyNameComponent,
OpportunityNameComponent,
OfferingNameComponent,
StageButtonsComponent,
AccountCellComponent,
FormattedCellComponent
} from './cells';
import {Component, Directive} from '@angular/core'; import {Component, Directive} from '@angular/core';
import { import {AccountCellComponent, CompanyNameComponent, FormattedCellComponent, OfferingNameComponent, OpportunityNameComponent, StageButtonsComponent} from './cells';
Offering, import {AAT_STATUS_WIDTH, ACCOUNT_CELL_WIDTH, BASE_POINTS_WIDTH, BUNDLES_WIDTH, COMPANY_NAME_WIDTH, DUE_DATE_WIDTH, END_DATE_WIDTH, ITEM_HEIGHT, KICKER_POINTS_WIDTH, OFFERING_NAME_WIDTH, OPPORTUNITY_NAME_WIDTH, Offering, STAGE_BUTTONS_WIDTH} from './common';
ITEM_HEIGHT,
COMPANY_NAME_WIDTH,
OPPORTUNITY_NAME_WIDTH,
OFFERING_NAME_WIDTH,
ACCOUNT_CELL_WIDTH,
BASE_POINTS_WIDTH,
KICKER_POINTS_WIDTH,
STAGE_BUTTONS_WIDTH,
BUNDLES_WIDTH,
DUE_DATE_WIDTH,
END_DATE_WIDTH,
AAT_STATUS_WIDTH
} from './common';
@Component({ @Component({
selector: 'scroll-item', selector: 'scroll-item',
inputs: ['offering'], inputs: ['offering'],
directives: [ directives: [
CompanyNameComponent, CompanyNameComponent, OpportunityNameComponent, OfferingNameComponent, StageButtonsComponent,
OpportunityNameComponent, AccountCellComponent, FormattedCellComponent
OfferingNameComponent,
StageButtonsComponent,
AccountCellComponent,
FormattedCellComponent
], ],
template: ` template: `
<div class="row" <div class="row"

View File

@ -1,6 +1,6 @@
import {Component, NgModule} from 'angular2/core';
import {BrowserModule} from '@angular/platform-browser'; import {BrowserModule} from '@angular/platform-browser';
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {Component, NgModule} from 'angular2/core';
@Component({selector: 'app', template: '<h1>Page Load Time</h1>'}) @Component({selector: 'app', template: '<h1>Page Load Time</h1>'})
class App { class App {

View File

@ -3,18 +3,12 @@ import {Component, NgModule} from '@angular/core';
import {ApplicationRef} from '@angular/core/src/application_ref'; import {ApplicationRef} from '@angular/core/src/application_ref';
import {reflector} from '@angular/core/src/reflection/reflection'; import {reflector} from '@angular/core/src/reflection/reflection';
import {ReflectionCapabilities} from '@angular/core/src/reflection/reflection_capabilities'; import {ReflectionCapabilities} from '@angular/core/src/reflection/reflection_capabilities';
import {DOM} from '@angular/platform-browser/src/dom/dom_adapter'; import {document, gc, window} from '@angular/facade/src/browser';
import {window, document, gc} from '@angular/facade/src/browser';
import {
getIntParameter,
getStringParameter,
bindAction,
windowProfile,
windowProfileEnd
} from '@angular/testing/src/benchmark_util';
import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter';
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {BrowserModule} from '@angular/platform-browser'; import {BrowserModule} from '@angular/platform-browser';
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter';
import {DOM} from '@angular/platform-browser/src/dom/dom_adapter';
import {bindAction, getIntParameter, getStringParameter, windowProfile, windowProfileEnd} from '@angular/testing/src/benchmark_util';
function createBindings(): any[] { function createBindings(): any[] {
return []; return [];
@ -92,8 +86,7 @@ export function main() {
} }
function initNg2() { function initNg2() {
platformBrowserDynamic().bootstrapModule(AppModule) platformBrowserDynamic().bootstrapModule(AppModule).then((ref) => {
.then((ref) => {
var injector = ref.injector; var injector = ref.injector;
appRef = injector.get(ApplicationRef); appRef = injector.get(ApplicationRef);
@ -118,7 +111,8 @@ export function main() {
bindAction('#baselineCreateDom', baselineCreateDom); bindAction('#baselineCreateDom', baselineCreateDom);
bindAction('#baselineUpdateDomProfile', profile(baselineCreateDom, noop, 'baseline-update')); bindAction('#baselineUpdateDomProfile', profile(baselineCreateDom, noop, 'baseline-update'));
bindAction('#baselineCreateDomProfile', bindAction(
'#baselineCreateDomProfile',
profile(baselineCreateDom, baselineDestroyDom, 'baseline-create')); profile(baselineCreateDom, baselineDestroyDom, 'baseline-create'));
} }
@ -139,7 +133,8 @@ class TreeNode {
function buildTree(maxDepth, values, curDepth) { function buildTree(maxDepth, values, curDepth) {
if (maxDepth === curDepth) return new TreeNode('', null, null); if (maxDepth === curDepth) return new TreeNode('', null, null);
return new TreeNode(values[curDepth], buildTree(maxDepth, values, curDepth + 1), return new TreeNode(
values[curDepth], buildTree(maxDepth, values, curDepth + 1),
buildTree(maxDepth, values, curDepth + 1)); buildTree(maxDepth, values, curDepth + 1));
} }
@ -233,7 +228,8 @@ class StaticTreeComponent0 extends StaticTreeComponentBase {
selector: 'tree', selector: 'tree',
inputs: ['data'], inputs: ['data'],
directives: [StaticTreeComponent0], directives: [StaticTreeComponent0],
template: `<span> {{data.value}} <tree [data]='data.right'></tree><tree [data]='data.left'></tree></span>` template:
`<span> {{data.value}} <tree [data]='data.right'></tree><tree [data]='data.left'></tree></span>`
}) })
class StaticTreeComponent1 extends StaticTreeComponentBase { class StaticTreeComponent1 extends StaticTreeComponentBase {
} }
@ -242,7 +238,8 @@ class StaticTreeComponent1 extends StaticTreeComponentBase {
selector: 'tree', selector: 'tree',
inputs: ['data'], inputs: ['data'],
directives: [StaticTreeComponent1], directives: [StaticTreeComponent1],
template: `<span> {{data.value}} <tree [data]='data.right'></tree><tree [data]='data.left'></tree></span>` template:
`<span> {{data.value}} <tree [data]='data.right'></tree><tree [data]='data.left'></tree></span>`
}) })
class StaticTreeComponent2 extends StaticTreeComponentBase { class StaticTreeComponent2 extends StaticTreeComponentBase {
data: TreeNode; data: TreeNode;
@ -252,7 +249,8 @@ class StaticTreeComponent2 extends StaticTreeComponentBase {
selector: 'tree', selector: 'tree',
inputs: ['data'], inputs: ['data'],
directives: [StaticTreeComponent2], directives: [StaticTreeComponent2],
template: `<span> {{data.value}} <tree [data]='data.right'></tree><tree [data]='data.left'></tree></span>` template:
`<span> {{data.value}} <tree [data]='data.right'></tree><tree [data]='data.left'></tree></span>`
}) })
class StaticTreeComponent3 extends StaticTreeComponentBase { class StaticTreeComponent3 extends StaticTreeComponentBase {
} }
@ -261,7 +259,8 @@ class StaticTreeComponent3 extends StaticTreeComponentBase {
selector: 'tree', selector: 'tree',
inputs: ['data'], inputs: ['data'],
directives: [StaticTreeComponent3], directives: [StaticTreeComponent3],
template: `<span> {{data.value}} <tree [data]='data.right'></tree><tree [data]='data.left'></tree></span>` template:
`<span> {{data.value}} <tree [data]='data.right'></tree><tree [data]='data.left'></tree></span>`
}) })
class StaticTreeComponent4 extends StaticTreeComponentBase { class StaticTreeComponent4 extends StaticTreeComponentBase {
} }
@ -270,7 +269,8 @@ class StaticTreeComponent4 extends StaticTreeComponentBase {
selector: 'tree', selector: 'tree',
inputs: ['data'], inputs: ['data'],
directives: [StaticTreeComponent4], directives: [StaticTreeComponent4],
template: `<span> {{data.value}} <tree [data]='data.right'></tree><tree [data]='data.left'></tree></span>` template:
`<span> {{data.value}} <tree [data]='data.right'></tree><tree [data]='data.left'></tree></span>`
}) })
class StaticTreeComponent5 extends StaticTreeComponentBase { class StaticTreeComponent5 extends StaticTreeComponentBase {
} }
@ -279,7 +279,8 @@ class StaticTreeComponent5 extends StaticTreeComponentBase {
selector: 'tree', selector: 'tree',
inputs: ['data'], inputs: ['data'],
directives: [StaticTreeComponent5], directives: [StaticTreeComponent5],
template: `<span> {{data.value}} <tree [data]='data.right'></tree><tree [data]='data.left'></tree></span>` template:
`<span> {{data.value}} <tree [data]='data.right'></tree><tree [data]='data.left'></tree></span>`
}) })
class StaticTreeComponent6 extends StaticTreeComponentBase { class StaticTreeComponent6 extends StaticTreeComponentBase {
} }
@ -288,7 +289,8 @@ class StaticTreeComponent6 extends StaticTreeComponentBase {
selector: 'tree', selector: 'tree',
inputs: ['data'], inputs: ['data'],
directives: [StaticTreeComponent6], directives: [StaticTreeComponent6],
template: `<span> {{data.value}} <tree [data]='data.right'></tree><tree [data]='data.left'></tree></span>` template:
`<span> {{data.value}} <tree [data]='data.right'></tree><tree [data]='data.left'></tree></span>`
}) })
class StaticTreeComponent7 extends StaticTreeComponentBase { class StaticTreeComponent7 extends StaticTreeComponentBase {
} }
@ -297,7 +299,8 @@ class StaticTreeComponent7 extends StaticTreeComponentBase {
selector: 'tree', selector: 'tree',
inputs: ['data'], inputs: ['data'],
directives: [StaticTreeComponent7], directives: [StaticTreeComponent7],
template: `<span> {{data.value}} <tree [data]='data.right'></tree><tree [data]='data.left'></tree></span>` template:
`<span> {{data.value}} <tree [data]='data.right'></tree><tree [data]='data.left'></tree></span>`
}) })
class StaticTreeComponent8 extends StaticTreeComponentBase { class StaticTreeComponent8 extends StaticTreeComponentBase {
} }
@ -306,7 +309,8 @@ class StaticTreeComponent8 extends StaticTreeComponentBase {
selector: 'tree', selector: 'tree',
inputs: ['data'], inputs: ['data'],
directives: [StaticTreeComponent8], directives: [StaticTreeComponent8],
template: `<span> {{data.value}} <tree [data]='data.right'></tree><tree [data]='data.left'></tree></span>` template:
`<span> {{data.value}} <tree [data]='data.right'></tree><tree [data]='data.left'></tree></span>`
}) })
class StaticTreeComponent9 extends StaticTreeComponentBase { class StaticTreeComponent9 extends StaticTreeComponentBase {
} }

View File

@ -1,12 +1,7 @@
import { import {getIntParameter, windowProfile, windowProfileEnd} from '@angular/platform-browser/testing/benchmark_util';
getIntParameter,
windowProfile,
windowProfileEnd
} from '@angular/platform-browser/testing/benchmark_util';
export class TreeNode { export class TreeNode {
constructor(public value: string, public left: TreeNode, public right: TreeNode) { constructor(public value: string, public left: TreeNode, public right: TreeNode) {}
}
} }
let treeCreateCount: number; let treeCreateCount: number;
@ -21,7 +16,7 @@ function init() {
treeCreateCount = 0; treeCreateCount = 0;
numberData = []; numberData = [];
charData = []; charData = [];
for (let i = 0; i<maxDepth; i++) { for (let i = 0; i < maxDepth; i++) {
numberData.push(i.toString()); numberData.push(i.toString());
charData.push(String.fromCharCode('A'.charCodeAt(0) + i)); charData.push(String.fromCharCode('A'.charCodeAt(0) + i));
} }
@ -29,8 +24,8 @@ function init() {
function _buildTree(values: string[], curDepth: number = 0): TreeNode { function _buildTree(values: string[], curDepth: number = 0): TreeNode {
if (maxDepth === curDepth) return new TreeNode('', null, null); if (maxDepth === curDepth) return new TreeNode('', null, null);
return new TreeNode(values[curDepth], _buildTree(values, curDepth + 1), return new TreeNode(
_buildTree(values, curDepth + 1)); values[curDepth], _buildTree(values, curDepth + 1), _buildTree(values, curDepth + 1));
} }
export function emptyTree(): TreeNode { export function emptyTree(): TreeNode {
@ -69,4 +64,4 @@ export function profile(create: () => void, destroy: () => void, name: string) {
windowProfileEnd(name + ' w/o GC'); windowProfileEnd(name + ' w/o GC');
window.console.log(`Iterations: ${count}; time: ${duration / count} ms / iteration`); window.console.log(`Iterations: ${count}; time: ${duration / count} ms / iteration`);
}; };
} }

View File

@ -3,9 +3,10 @@ import {TreeNode} from '../../app/util';
// http://jsperf.com/nextsibling-vs-childnodes // http://jsperf.com/nextsibling-vs-childnodes
const BASELINE_TREE_TEMPLATE =document.createElement('template'); const BASELINE_TREE_TEMPLATE = document.createElement('template');
BASELINE_TREE_TEMPLATE.innerHTML = '<span>_<template class="ng-provider"></template><template class="ng-provider"></template></span>'; BASELINE_TREE_TEMPLATE.innerHTML =
const BASELINE_IF_TEMPLATE =document.createElement('template'); '<span>_<template class="ng-provider"></template><template class="ng-provider"></template></span>';
const BASELINE_IF_TEMPLATE = document.createElement('template');
BASELINE_IF_TEMPLATE.innerHTML = '<span template="if"><tree></tree></span>'; BASELINE_IF_TEMPLATE.innerHTML = '<span template="if"><tree></tree></span>';
export class BaseLineTreeComponent { export class BaseLineTreeComponent {
@ -32,9 +33,7 @@ export class BaseLineTreeComponent {
export class BaseLineInterpolation { export class BaseLineInterpolation {
value: string; value: string;
constructor(public textNode: Node) { constructor(public textNode: Node) { this.value = null; }
this.value = null;
}
update(value: string) { update(value: string) {
if (this.value !== value) { if (this.value !== value) {
this.value = value; this.value = value;

View File

@ -1,19 +1,16 @@
import { import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter';
bindAction import {bindAction} from '@angular/platform-browser/testing/benchmark_util';
} from '@angular/platform-browser/testing/benchmark_util';
import {TreeNode, buildTree, emptyTree, profile} from '../app/util';
import {BaseLineTreeComponent} from './app/tree'; import {BaseLineTreeComponent} from './app/tree';
import {TreeNode, buildTree, emptyTree, profile} from '../app/util';
import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter';
export function main() { export function main() {
var app: BaseLineTreeComponent; var app: BaseLineTreeComponent;
function destroyDom() { app.update(emptyTree()); } function destroyDom() { app.update(emptyTree()); }
function createDom() { function createDom() { app.update(buildTree()); }
app.update(buildTree());
}
function noop() {} function noop() {}
@ -27,8 +24,7 @@ export function main() {
bindAction('#createDom', createDom); bindAction('#createDom', createDom);
bindAction('#updateDomProfile', profile(createDom, noop, 'baseline-update')); bindAction('#updateDomProfile', profile(createDom, noop, 'baseline-update'));
bindAction('#createDomProfile', bindAction('#createDomProfile', profile(createDom, destroyDom, 'baseline-create'));
profile(createDom, destroyDom, 'baseline-create'));
} }
init(); init();

View File

@ -1,7 +1,4 @@
import { import {Component, NgModule} from '@angular/core';
Component,
NgModule
} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser'; import {BrowserModule} from '@angular/platform-browser';
import {TreeNode, emptyTree} from '../../app/util'; import {TreeNode, emptyTree} from '../../app/util';
@ -16,13 +13,10 @@ class TreeComponent {
data: TreeNode; data: TreeNode;
} }
@Component( @Component({selector: 'app', template: `<tree [data]='initData'></tree>`})
{selector: 'app', template: `<tree [data]='initData'></tree>`})
export class AppComponent { export class AppComponent {
initData: TreeNode; initData: TreeNode;
constructor() { constructor() { this.initData = emptyTree(); }
this.initData = emptyTree();
}
} }
@NgModule({ @NgModule({
@ -30,4 +24,5 @@ export class AppComponent {
bootstrap: [AppComponent], bootstrap: [AppComponent],
declarations: [TreeComponent, AppComponent] declarations: [TreeComponent, AppComponent]
}) })
export class AppModule {} export class AppModule {
}

View File

@ -1,18 +1,11 @@
import { import {NgModule, enableProdMode} from '@angular/core';
NgModule,
enableProdMode
} from '@angular/core';
import {ApplicationRef} from '@angular/core/src/application_ref'; import {ApplicationRef} from '@angular/core/src/application_ref';
import {
bindAction,
windowProfile,
windowProfileEnd
} from '@angular/platform-browser/testing/benchmark_util';
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic'; import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {bindAction, windowProfile, windowProfileEnd} from '@angular/platform-browser/testing/benchmark_util';
import {TreeNode, buildTree, emptyTree, profile} from '../app/util';
import {AppComponent, AppModule} from './app/tree'; import {AppComponent, AppModule} from './app/tree';
import {TreeNode, buildTree, emptyTree, profile} from '../app/util';
export function main() { export function main() {
var app: AppComponent; var app: AppComponent;
@ -32,8 +25,7 @@ export function main() {
function init() { function init() {
enableProdMode(); enableProdMode();
platformBrowserDynamic().bootstrapModule(AppModule) platformBrowserDynamic().bootstrapModule(AppModule).then((ref) => {
.then((ref) => {
var injector = ref.injector; var injector = ref.injector;
appRef = injector.get(ApplicationRef); appRef = injector.get(ApplicationRef);

View File

@ -11,8 +11,7 @@
</template> </template>
</span> </span>
</template> </template>
</dom-module> <script>
<script>
Polymer({ Polymer({
is: 'binary-tree', is: 'binary-tree',
properties: { properties: {
@ -21,4 +20,5 @@
leftTree: null, leftTree: null,
rightTree: null rightTree: null
}); });
</script> </script>
</dom-module>

View File

@ -1,7 +1,6 @@
import {bindAction} from '@angular/platform-browser/testing/benchmark_util';
import {buildTree, emptyTree} from '../app/util'; import {buildTree, emptyTree} from '../app/util';
import {
bindAction
} from '@angular/platform-browser/testing/benchmark_util';
declare var Polymer: any; declare var Polymer: any;
@ -9,13 +8,9 @@ export function main() {
const rootEl: any = document.querySelector('binary-tree'); const rootEl: any = document.querySelector('binary-tree');
rootEl.data = emptyTree(); rootEl.data = emptyTree();
function destroyDom() { function destroyDom() { rootEl.data = emptyTree(); }
rootEl.data = emptyTree();
}
function createDom() { function createDom() { rootEl.data = buildTree(); }
rootEl.data = buildTree();
}
bindAction('#destroyDom', destroyDom); bindAction('#destroyDom', destroyDom);
bindAction('#createDom', createDom); bindAction('#createDom', createDom);