feat(benchmarks): add incremental-dom version of deep tree benchmark

This commit is contained in:
Tobias Bosch 2016-09-01 10:31:31 -07:00 committed by Martin Probst
parent 27d72e87c3
commit 2581c0851a
11 changed files with 107 additions and 7 deletions

View File

@ -45,6 +45,7 @@ ln -s ../../../../node_modules/reflect-metadata/Reflect.js .
ln -s ../../../../node_modules/rxjs .
ln -s ../../../../node_modules/angular/angular.js .
ln -s ../../../../bower_components/polymer .
ln -s ../../../../node_modules/incremental-dom/dist/incremental-dom-cjs.js
cd -
TSCONFIG=./modules/tsconfig.json

View File

@ -41,6 +41,15 @@ describe('tree benchmark perf', () => {
ignoreBrowserSynchronization: true,
}).then(done, done.fail);
});
it('should run for the incremental dom', (done) => {
runTreeBenchmark({
id: 'deepTree.incrementalDom',
url: 'all/benchmarks/src/tree/incremental_dom/index.html',
ignoreBrowserSynchronization: true,
}).then(done, done.fail);
});
it('should run for polymer binary tree', (done) => {
runTreeBenchmark({
id: 'deepTree.polymer',

View File

@ -37,6 +37,14 @@ describe('tree benchmark spec', () => {
ignoreBrowserSynchronization: true,
});
});
it('should work for the incremental dom', () => {
testTreeBenchmark({
url: 'all/benchmarks/src/tree/incremental_dom/index.html',
ignoreBrowserSynchronization: true,
});
});
it('should work for polymer binary tree', () => {
testTreeBenchmark({
url: 'all/benchmarks/src/tree/polymer/index.html',

View File

@ -14,7 +14,10 @@
(<any>global).benchmarksBootstrap = benchmarksBootstrap;
function benchmarksBootstrap() {
System.config({defaultJSExtensions: true});
System.config({
defaultJSExtensions: true,
map: {'incremental-dom': '/all/benchmarks/vendor/incremental-dom-cjs.js'}
});
// BOOTSTRAP the app!
System.import('index').then(function(m: any) { m.main(); }, console.error.bind(console));

View File

@ -18,8 +18,8 @@ export function main() {
bindAction('#destroyDom', destroyDom);
bindAction('#createDom', createDom);
bindAction('#updateDomProfile', profile(createDom, noop, 'baseline-update'));
bindAction('#createDomProfile', profile(createDom, destroyDom, 'baseline-create'));
bindAction('#updateDomProfile', profile(createDom, noop, 'update'));
bindAction('#createDomProfile', profile(createDom, destroyDom, 'create'));
}
init();

View File

@ -0,0 +1,27 @@
<!doctype html>
<html>
<body>
<h2>Params</h2>
<form>
Depth:
<input type="number" name="depth" placeholder="depth" value="9">
<br>
<button>Apply</button>
</form>
<h2>Baseline tree benchmark</h2>
<p>
<button id="destroyDom">destroyDom</button>
<button id="createDom">createDom</button>
<button id="updateDomProfile">profile updateDom</button>
<button id="createDomProfile">profile createDom</button>
</p>
<div>
<tree id="root"></tree>
</div>
<script src="../../bootstrap_plain.js"></script>
</body>
</html>

View File

@ -0,0 +1,26 @@
import {bindAction, profile} from '../../util';
import {TreeNode, buildTree, emptyTree} from '../util';
import {render} from './tree';
const {patch} = require('incremental-dom');
export function main() {
var app: any;
function destroyDom() { patch(app, () => render(emptyTree)); }
function createDom() { patch(app, () => render(buildTree())); }
function noop() {}
function init() {
app = document.querySelector('tree');
bindAction('#destroyDom', destroyDom);
bindAction('#createDom', createDom);
bindAction('#updateDomProfile', profile(createDom, noop, 'update'));
bindAction('#createDomProfile', profile(createDom, destroyDom, 'create'));
}
init();
}

View File

@ -0,0 +1,26 @@
import {TreeNode} from '../util';
const {elementOpen, elementClose, text} = require('incremental-dom');
// template:
// <span> {{data.value}} <span template='ngIf data.right != null'><tree
// [data]='data.right'></tree></span><span template='ngIf data.left != null'><tree
// [data]='data.left'></tree></span></span>
export function render(data: TreeNode) {
elementOpen('span', '', null);
text(` ${data.value} `);
if (data.left) {
elementOpen('span', '', null);
elementOpen('tree', '', null);
render(data.left);
elementClose('tree');
elementClose('span');
}
if (data.right) {
elementOpen('span', '', null);
elementOpen('tree', '', null);
render(data.right);
elementClose('tree');
elementClose('span');
}
elementClose('span');
}

View File

@ -31,8 +31,8 @@ export function main() {
tree = appRef.components[0].instance;
bindAction('#destroyDom', destroyDom);
bindAction('#createDom', createDom);
bindAction('#updateDomProfile', profile(createDom, noop, 'ng2-update'));
bindAction('#createDomProfile', profile(createDom, destroyDom, 'ng2-create'));
bindAction('#updateDomProfile', profile(createDom, noop, 'update'));
bindAction('#createDomProfile', profile(createDom, destroyDom, 'create'));
});
}

View File

@ -23,7 +23,7 @@
<binary-tree id="root"></binary-tree>
</div>
<script src="../../bootstrap_polymer.js"></script>
<script src="../../bootstrap_plain.js"></script>
</body>
</html>

View File

@ -23,7 +23,7 @@
<binary-tree id="root"></binary-tree>
</div>
<script src="../../bootstrap_polymer.js"></script>
<script src="../../bootstrap_plain.js"></script>
</body>
</html>