refactor(benchmarks): make tree benchmark work again
This commit is contained in:

committed by
Victor Berchet

parent
5ff14de1f3
commit
61002733bc
83
modules/benchmarks_external/src/bootstrap.ts
Normal file
83
modules/benchmarks_external/src/bootstrap.ts
Normal file
@ -0,0 +1,83 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
|
||||
(function(global: any /** TODO #9100 */) {
|
||||
|
||||
writeScriptTag('/all/benchmarks/vendor/core.js');
|
||||
writeScriptTag('/all/benchmarks/vendor/zone.js');
|
||||
writeScriptTag('/all/benchmarks/vendor/long-stack-trace-zone.js');
|
||||
writeScriptTag('/all/benchmarks/vendor/system.src.js');
|
||||
writeScriptTag('/all/benchmarks/vendor/Reflect.js', 'benchmarksBootstrap()');
|
||||
|
||||
(<any>global).benchmarksBootstrap = benchmarksBootstrap;
|
||||
|
||||
function benchmarksBootstrap() {
|
||||
// check query param
|
||||
var useBundles = location.search.indexOf('bundles=false') == -1;
|
||||
if (useBundles) {
|
||||
System.config({
|
||||
map: {
|
||||
'index': 'index.js',
|
||||
'@angular/core': '/packages-dist/core/bundles/core.umd.js',
|
||||
'@angular/common': '/packages-dist/common/bundles/common.umd.js',
|
||||
'@angular/forms': '/packages-dist/forms/bundles/forms.umd.js',
|
||||
'@angular/compiler': '/packages-dist/compiler/bundles/compiler.umd.js',
|
||||
'@angular/platform-browser':
|
||||
'/packages-dist/platform-browser/bundles/platform-browser.umd.js',
|
||||
'@angular/platform-browser-dynamic':
|
||||
'/packages-dist/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
|
||||
'@angular/http': '/packages-dist/http/bundles/http.umd.js',
|
||||
'@angular/upgrade': '/packages-dist/upgrade/bundles/upgrade.umd.js',
|
||||
'@angular/router': '/packages-dist/router/bundles/router.umd.js',
|
||||
'@angular/core/src/facade': '/all/@angular/core/src/facade',
|
||||
'rxjs': '/all/benchmarks/vendor/rxjs'
|
||||
},
|
||||
packages: {
|
||||
'app': {defaultExtension: 'js'},
|
||||
'@angular/core/src/facade': {defaultExtension: 'js'},
|
||||
'rxjs': {defaultExtension: 'js'}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.warn(
|
||||
'Not using the Angular bundles. Don\'t use this configuration for e2e/performance tests!');
|
||||
|
||||
System.config({
|
||||
map: {
|
||||
'index': 'index.js',
|
||||
'@angular': '/all/@angular',
|
||||
'rxjs': '/all/benchmarks/vendor/rxjs'
|
||||
},
|
||||
packages: {
|
||||
'app': {defaultExtension: 'js'},
|
||||
'@angular/core': {main: 'index.js', defaultExtension: 'js'},
|
||||
'@angular/compiler': {main: 'index.js', defaultExtension: 'js'},
|
||||
'@angular/router': {main: 'index.js', defaultExtension: 'js'},
|
||||
'@angular/common': {main: 'index.js', defaultExtension: 'js'},
|
||||
'@angular/forms': {main: 'index.js', defaultExtension: 'js'},
|
||||
'@angular/platform-browser': {main: 'index.js', defaultExtension: 'js'},
|
||||
'@angular/platform-browser-dynamic': {main: 'index.js', defaultExtension: 'js'},
|
||||
'@angular/upgrade': {main: 'index.js', defaultExtension: 'js'},
|
||||
'rxjs': {defaultExtension: 'js'}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// BOOTSTRAP the app!
|
||||
System.import('index').then(function(m: any /** TODO #9100 */) {
|
||||
m.main();
|
||||
}, console.error.bind(console));
|
||||
}
|
||||
|
||||
|
||||
function writeScriptTag(scriptUrl: any /** TODO #9100 */, onload?: any /** TODO #9100 */) {
|
||||
document.write(`<script src="${scriptUrl}" onload="${onload}"></script>`);
|
||||
}
|
||||
}(window));
|
@ -1,24 +0,0 @@
|
||||
<link rel="import" href="polymer.html">
|
||||
<dom-module id="binary-tree">
|
||||
<template>
|
||||
<span>
|
||||
<span>{{data.value}}</span>
|
||||
<template is="dom-if" if="[[data.left]]">
|
||||
<binary-tree data="[[data.left]]"></binary-tree>
|
||||
</template>
|
||||
<template is="dom-if" if="[[data.right]]">
|
||||
<binary-tree data="[[data.right]]"></binary-tree>
|
||||
</template>
|
||||
</span>
|
||||
</template>
|
||||
</dom-module>
|
||||
<script>
|
||||
Polymer({
|
||||
is: 'binary-tree',
|
||||
properties: {
|
||||
data: Object
|
||||
},
|
||||
leftTree: null,
|
||||
rightTree: null
|
||||
});
|
||||
</script>
|
@ -1,22 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<link rel="import" href="root_tree.html">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h2>Params</h2>
|
||||
<form>
|
||||
Depth:
|
||||
<input type="number" name="depth" placeholder="depth" value="9">
|
||||
<br>
|
||||
<button>Apply</button>
|
||||
</form>
|
||||
|
||||
<h2>Polymer JS 1.x tree benchmark</h2>
|
||||
<root-tree></root-tree>
|
||||
|
||||
<script src="url_params_to_form.js" type="text/javascript"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,49 +0,0 @@
|
||||
<link rel="import" href="polymer.html">
|
||||
<link rel="import" href="binary_tree.html">
|
||||
|
||||
<dom-module id="root-tree">
|
||||
<template>
|
||||
<div>
|
||||
<button on-click="create" id="createDom">createDom</button>
|
||||
<button on-click="destroy" id="destroyDom">destroyDom</button>
|
||||
</div>
|
||||
<div>
|
||||
<binary-tree data="[[data]]"></binary-tree>
|
||||
</div>
|
||||
</template>
|
||||
</dom-module>
|
||||
<script type="application/javascript">
|
||||
(function() {
|
||||
var count = 0;
|
||||
var depthInput = document.querySelector('input[name=depth]');
|
||||
var match = /depth=(\w+)/.exec(decodeURIComponent(location.search));
|
||||
if (match) {
|
||||
depthInput.value = match[1];
|
||||
}
|
||||
var maxDepth = depthInput.valueAsNumber;
|
||||
Polymer({
|
||||
is: 'root-tree',
|
||||
properties: {
|
||||
data: Object
|
||||
},
|
||||
create: function() {
|
||||
var values = count++ % 2 == 0 ?
|
||||
['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '*'] :
|
||||
['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', '-'];
|
||||
|
||||
this.data = this.buildTree(maxDepth, values, 0);
|
||||
},
|
||||
destroy: function() {
|
||||
this.data = null;
|
||||
},
|
||||
buildTree: function(maxDepth, values, curDepth) {
|
||||
if (maxDepth == curDepth) return {value: '', left: null, right: null};
|
||||
return {
|
||||
value: values[curDepth],
|
||||
left: this.buildTree(maxDepth, values, curDepth+1),
|
||||
right: this.buildTree(maxDepth, values, curDepth+1)
|
||||
};
|
||||
}
|
||||
});
|
||||
})();
|
||||
</script>
|
Reference in New Issue
Block a user