
committed by
Victor Berchet

parent
61002733bc
commit
c377e80670
@ -1,12 +1,7 @@
|
||||
import {
|
||||
getIntParameter,
|
||||
windowProfile,
|
||||
windowProfileEnd
|
||||
} from '@angular/platform-browser/testing/benchmark_util';
|
||||
import {getIntParameter, windowProfile, windowProfileEnd} from '@angular/platform-browser/testing/benchmark_util';
|
||||
|
||||
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;
|
||||
@ -21,7 +16,7 @@ function init() {
|
||||
treeCreateCount = 0;
|
||||
numberData = [];
|
||||
charData = [];
|
||||
for (let i = 0; i<maxDepth; i++) {
|
||||
for (let i = 0; i < maxDepth; i++) {
|
||||
numberData.push(i.toString());
|
||||
charData.push(String.fromCharCode('A'.charCodeAt(0) + i));
|
||||
}
|
||||
@ -29,8 +24,8 @@ function init() {
|
||||
|
||||
function _buildTree(values: string[], curDepth: number = 0): TreeNode {
|
||||
if (maxDepth === curDepth) return new TreeNode('', null, null);
|
||||
return new TreeNode(values[curDepth], _buildTree(values, curDepth + 1),
|
||||
_buildTree(values, curDepth + 1));
|
||||
return new TreeNode(
|
||||
values[curDepth], _buildTree(values, curDepth + 1), _buildTree(values, curDepth + 1));
|
||||
}
|
||||
|
||||
export function emptyTree(): TreeNode {
|
||||
@ -43,30 +38,30 @@ export function buildTree(): TreeNode {
|
||||
}
|
||||
|
||||
export function profile(create: () => void, destroy: () => void, name: string) {
|
||||
return function() {
|
||||
windowProfile(name + ' w GC');
|
||||
var duration = 0;
|
||||
var count = 0;
|
||||
while (count++ < 150) {
|
||||
(<any>window)['gc']();
|
||||
var start = window.performance.now();
|
||||
create();
|
||||
duration += window.performance.now() - start;
|
||||
destroy();
|
||||
}
|
||||
windowProfileEnd(name + ' w GC');
|
||||
window.console.log(`Iterations: ${count}; time: ${duration / count} ms / iteration`);
|
||||
return function() {
|
||||
windowProfile(name + ' w GC');
|
||||
var duration = 0;
|
||||
var count = 0;
|
||||
while (count++ < 150) {
|
||||
(<any>window)['gc']();
|
||||
var start = window.performance.now();
|
||||
create();
|
||||
duration += window.performance.now() - start;
|
||||
destroy();
|
||||
}
|
||||
windowProfileEnd(name + ' w GC');
|
||||
window.console.log(`Iterations: ${count}; time: ${duration / count} ms / iteration`);
|
||||
|
||||
windowProfile(name + ' w/o GC');
|
||||
duration = 0;
|
||||
count = 0;
|
||||
while (count++ < 150) {
|
||||
var start = window.performance.now();
|
||||
create();
|
||||
duration += window.performance.now() - start;
|
||||
destroy();
|
||||
}
|
||||
windowProfileEnd(name + ' w/o GC');
|
||||
window.console.log(`Iterations: ${count}; time: ${duration / count} ms / iteration`);
|
||||
};
|
||||
}
|
||||
windowProfile(name + ' w/o GC');
|
||||
duration = 0;
|
||||
count = 0;
|
||||
while (count++ < 150) {
|
||||
var start = window.performance.now();
|
||||
create();
|
||||
duration += window.performance.now() - start;
|
||||
destroy();
|
||||
}
|
||||
windowProfileEnd(name + ' w/o GC');
|
||||
window.console.log(`Iterations: ${count}; time: ${duration / count} ms / iteration`);
|
||||
};
|
||||
}
|
@ -3,9 +3,10 @@ import {TreeNode} from '../../app/util';
|
||||
|
||||
// http://jsperf.com/nextsibling-vs-childnodes
|
||||
|
||||
const BASELINE_TREE_TEMPLATE =document.createElement('template');
|
||||
BASELINE_TREE_TEMPLATE.innerHTML = '<span>_<template class="ng-provider"></template><template class="ng-provider"></template></span>';
|
||||
const BASELINE_IF_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>';
|
||||
const BASELINE_IF_TEMPLATE = document.createElement('template');
|
||||
BASELINE_IF_TEMPLATE.innerHTML = '<span template="if"><tree></tree></span>';
|
||||
|
||||
export class BaseLineTreeComponent {
|
||||
@ -32,9 +33,7 @@ export class BaseLineTreeComponent {
|
||||
|
||||
export class BaseLineInterpolation {
|
||||
value: string;
|
||||
constructor(public textNode: Node) {
|
||||
this.value = null;
|
||||
}
|
||||
constructor(public textNode: Node) { this.value = null; }
|
||||
update(value: string) {
|
||||
if (this.value !== value) {
|
||||
this.value = value;
|
||||
|
@ -1,19 +1,16 @@
|
||||
import {
|
||||
bindAction
|
||||
} from '@angular/platform-browser/testing/benchmark_util';
|
||||
import {BrowserDomAdapter} from '@angular/platform-browser/src/browser/browser_adapter';
|
||||
import {bindAction} from '@angular/platform-browser/testing/benchmark_util';
|
||||
|
||||
import {TreeNode, buildTree, emptyTree, profile} from '../app/util';
|
||||
|
||||
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() {
|
||||
var app: BaseLineTreeComponent;
|
||||
|
||||
function destroyDom() { app.update(emptyTree()); }
|
||||
|
||||
function createDom() {
|
||||
app.update(buildTree());
|
||||
}
|
||||
function createDom() { app.update(buildTree()); }
|
||||
|
||||
function noop() {}
|
||||
|
||||
@ -27,8 +24,7 @@ export function main() {
|
||||
bindAction('#createDom', createDom);
|
||||
|
||||
bindAction('#updateDomProfile', profile(createDom, noop, 'baseline-update'));
|
||||
bindAction('#createDomProfile',
|
||||
profile(createDom, destroyDom, 'baseline-create'));
|
||||
bindAction('#createDomProfile', profile(createDom, destroyDom, 'baseline-create'));
|
||||
}
|
||||
|
||||
init();
|
||||
|
@ -1,7 +1,4 @@
|
||||
import {
|
||||
Component,
|
||||
NgModule
|
||||
} from '@angular/core';
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
|
||||
import {TreeNode, emptyTree} from '../../app/util';
|
||||
@ -16,13 +13,10 @@ class TreeComponent {
|
||||
data: TreeNode;
|
||||
}
|
||||
|
||||
@Component(
|
||||
{selector: 'app', template: `<tree [data]='initData'></tree>`})
|
||||
@Component({selector: 'app', template: `<tree [data]='initData'></tree>`})
|
||||
export class AppComponent {
|
||||
initData: TreeNode;
|
||||
constructor() {
|
||||
this.initData = emptyTree();
|
||||
}
|
||||
constructor() { this.initData = emptyTree(); }
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
@ -30,4 +24,5 @@ export class AppComponent {
|
||||
bootstrap: [AppComponent],
|
||||
declarations: [TreeComponent, AppComponent]
|
||||
})
|
||||
export class AppModule {}
|
||||
export class AppModule {
|
||||
}
|
||||
|
@ -1,18 +1,11 @@
|
||||
import {
|
||||
NgModule,
|
||||
enableProdMode
|
||||
} from '@angular/core';
|
||||
|
||||
import {NgModule, enableProdMode} from '@angular/core';
|
||||
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 {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 {TreeNode, buildTree, emptyTree, profile} from '../app/util';
|
||||
|
||||
export function main() {
|
||||
var app: AppComponent;
|
||||
@ -32,17 +25,16 @@ export function main() {
|
||||
|
||||
function init() {
|
||||
enableProdMode();
|
||||
platformBrowserDynamic().bootstrapModule(AppModule)
|
||||
.then((ref) => {
|
||||
var injector = ref.injector;
|
||||
appRef = injector.get(ApplicationRef);
|
||||
platformBrowserDynamic().bootstrapModule(AppModule).then((ref) => {
|
||||
var injector = ref.injector;
|
||||
appRef = injector.get(ApplicationRef);
|
||||
|
||||
app = appRef.components[0].instance;
|
||||
bindAction('#destroyDom', destroyDom);
|
||||
bindAction('#createDom', createDom);
|
||||
bindAction('#updateDomProfile', profile(createDom, noop, 'ng2-update'));
|
||||
bindAction('#createDomProfile', profile(createDom, destroyDom, 'ng2-create'));
|
||||
});
|
||||
app = appRef.components[0].instance;
|
||||
bindAction('#destroyDom', destroyDom);
|
||||
bindAction('#createDom', createDom);
|
||||
bindAction('#updateDomProfile', profile(createDom, noop, 'ng2-update'));
|
||||
bindAction('#createDomProfile', profile(createDom, destroyDom, 'ng2-create'));
|
||||
});
|
||||
}
|
||||
|
||||
init();
|
||||
|
@ -11,14 +11,14 @@
|
||||
</template>
|
||||
</span>
|
||||
</template>
|
||||
<script>
|
||||
Polymer({
|
||||
is: 'binary-tree',
|
||||
properties: {
|
||||
data: Object
|
||||
},
|
||||
leftTree: null,
|
||||
rightTree: null
|
||||
});
|
||||
</script>
|
||||
</dom-module>
|
||||
<script>
|
||||
Polymer({
|
||||
is: 'binary-tree',
|
||||
properties: {
|
||||
data: Object
|
||||
},
|
||||
leftTree: null,
|
||||
rightTree: null
|
||||
});
|
||||
</script>
|
||||
|
@ -1,7 +1,6 @@
|
||||
import {bindAction} from '@angular/platform-browser/testing/benchmark_util';
|
||||
|
||||
import {buildTree, emptyTree} from '../app/util';
|
||||
import {
|
||||
bindAction
|
||||
} from '@angular/platform-browser/testing/benchmark_util';
|
||||
|
||||
declare var Polymer: any;
|
||||
|
||||
@ -9,13 +8,9 @@ export function main() {
|
||||
const rootEl: any = document.querySelector('binary-tree');
|
||||
rootEl.data = emptyTree();
|
||||
|
||||
function destroyDom() {
|
||||
rootEl.data = emptyTree();
|
||||
}
|
||||
function destroyDom() { rootEl.data = emptyTree(); }
|
||||
|
||||
function createDom() {
|
||||
rootEl.data = buildTree();
|
||||
}
|
||||
function createDom() { rootEl.data = buildTree(); }
|
||||
|
||||
bindAction('#destroyDom', destroyDom);
|
||||
bindAction('#createDom', createDom);
|
||||
|
Reference in New Issue
Block a user