refactor (benchmarks/): Ts'ifying benchmarks/
Translating AtScript in benchmarks/ to TypeScript.
This commit is contained in:
@ -1,17 +1,17 @@
|
||||
import {BrowserDomAdapter} from 'angular2/src/dom/browser_adapter';
|
||||
import {PromiseWrapper} from 'angular2/src/facade/async';
|
||||
import {ListWrapper, MapWrapper} from 'angular2/src/facade/collection';
|
||||
import {List, ListWrapper, Map, MapWrapper} from 'angular2/src/facade/collection';
|
||||
import {DateWrapper, Type, print} from 'angular2/src/facade/lang';
|
||||
import {NativeShadowDomStrategy} from 'angular2/src/render/dom/shadow_dom/native_shadow_dom_strategy';
|
||||
import {
|
||||
NativeShadowDomStrategy
|
||||
} from 'angular2/src/render/dom/shadow_dom/native_shadow_dom_strategy';
|
||||
|
||||
import {Parser, Lexer, DynamicChangeDetection} from 'angular2/change_detection';
|
||||
|
||||
import {Compiler, CompilerCache} from 'angular2/src/core/compiler/compiler';
|
||||
import {DirectiveResolver} from 'angular2/src/core/compiler/directive_resolver';
|
||||
|
||||
import {Component} from 'angular2/src/core/annotations_impl/annotations';
|
||||
import {Directive} from 'angular2/src/core/annotations_impl/annotations';
|
||||
import {View} from 'angular2/src/core/annotations_impl/view';
|
||||
import {Component, Directive, View} from 'angular2/angular2';
|
||||
import {TemplateLoader} from 'angular2/src/render/dom/compiler/template_loader';
|
||||
import {TemplateResolver} from 'angular2/src/core/compiler/template_resolver';
|
||||
import {UrlResolver} from 'angular2/src/services/url_resolver';
|
||||
@ -37,26 +37,18 @@ export function main() {
|
||||
var urlResolver = new UrlResolver();
|
||||
var styleUrlResolver = new StyleUrlResolver(urlResolver);
|
||||
var shadowDomStrategy = new NativeShadowDomStrategy(styleUrlResolver);
|
||||
var renderCompiler = new rc.DefaultDomCompiler(
|
||||
new Parser(new Lexer()), shadowDomStrategy, new TemplateLoader(null, urlResolver)
|
||||
);
|
||||
var compiler = new Compiler(
|
||||
reader,
|
||||
cache,
|
||||
templateResolver,
|
||||
new ComponentUrlMapper(),
|
||||
urlResolver,
|
||||
renderCompiler,
|
||||
new ProtoViewFactory(new DynamicChangeDetection(null))
|
||||
);
|
||||
var renderCompiler = new rc.DefaultDomCompiler(new Parser(new Lexer()), shadowDomStrategy,
|
||||
new TemplateLoader(null, urlResolver));
|
||||
var compiler =
|
||||
new Compiler(reader, cache, templateResolver, new ComponentUrlMapper(), urlResolver,
|
||||
renderCompiler, new ProtoViewFactory(new DynamicChangeDetection(null)));
|
||||
|
||||
function measureWrapper(func, desc) {
|
||||
return function() {
|
||||
var begin = DateWrapper.now();
|
||||
print(`[${desc}] Begin...`);
|
||||
var onSuccess = function(_) {
|
||||
var elapsedMs = DateWrapper.toMillis(
|
||||
DateWrapper.now()) - DateWrapper.toMillis(begin);
|
||||
var elapsedMs = DateWrapper.toMillis(DateWrapper.now()) - DateWrapper.toMillis(begin);
|
||||
print(`[${desc}] ...done, took ${elapsedMs} ms`);
|
||||
};
|
||||
PromiseWrapper.then(func(), onSuccess, null);
|
||||
@ -73,65 +65,39 @@ export function main() {
|
||||
return compiler.compile(BenchmarkComponentWithBindings);
|
||||
}
|
||||
|
||||
bindAction('#compileNoBindings',
|
||||
measureWrapper(compileNoBindings, 'No Bindings'));
|
||||
bindAction('#compileWithBindings',
|
||||
measureWrapper(compileWithBindings, 'With Bindings'));
|
||||
bindAction('#compileNoBindings', measureWrapper(compileNoBindings, 'No Bindings'));
|
||||
bindAction('#compileWithBindings', measureWrapper(compileWithBindings, 'With Bindings'));
|
||||
}
|
||||
|
||||
@Directive({
|
||||
selector: '[dir0]',
|
||||
properties: [
|
||||
'prop: attr0'
|
||||
]
|
||||
})
|
||||
class Dir0 {}
|
||||
@Directive({selector: '[dir0]', properties: ['prop: attr0']})
|
||||
class Dir0 {
|
||||
}
|
||||
|
||||
@Directive({
|
||||
selector: '[dir1]',
|
||||
properties: [
|
||||
'prop: attr1'
|
||||
]
|
||||
})
|
||||
@Directive({selector: '[dir1]', properties: ['prop: attr1']})
|
||||
class Dir1 {
|
||||
constructor(dir0:Dir0) {}
|
||||
constructor(dir0: Dir0) {}
|
||||
}
|
||||
|
||||
@Directive({
|
||||
selector: '[dir2]',
|
||||
properties: [
|
||||
'prop: attr2'
|
||||
]
|
||||
})
|
||||
@Directive({selector: '[dir2]', properties: ['prop: attr2']})
|
||||
class Dir2 {
|
||||
constructor(dir1:Dir1) {}
|
||||
constructor(dir1: Dir1) {}
|
||||
}
|
||||
|
||||
@Directive({
|
||||
selector: '[dir3]',
|
||||
properties: [
|
||||
'prop: attr3'
|
||||
]
|
||||
})
|
||||
@Directive({selector: '[dir3]', properties: ['prop: attr3']})
|
||||
class Dir3 {
|
||||
constructor(dir2:Dir2) {}
|
||||
constructor(dir2: Dir2) {}
|
||||
}
|
||||
|
||||
@Directive({
|
||||
selector: '[dir4]',
|
||||
properties: [
|
||||
'prop: attr4'
|
||||
]
|
||||
})
|
||||
@Directive({selector: '[dir4]', properties: ['prop: attr4']})
|
||||
class Dir4 {
|
||||
constructor(dir3:Dir3) {}
|
||||
constructor(dir3: Dir3) {}
|
||||
}
|
||||
|
||||
class MultipleTemplateResolver extends TemplateResolver {
|
||||
_multiple: num;
|
||||
_cache: Map;
|
||||
_multiple: number;
|
||||
_cache: Map<any, any>;
|
||||
|
||||
constructor(multiple: num, components: List) {
|
||||
constructor(multiple: number, components: List<Type>) {
|
||||
super();
|
||||
this._multiple = multiple;
|
||||
this._cache = MapWrapper.create();
|
||||
@ -149,10 +115,8 @@ class MultipleTemplateResolver extends TemplateResolver {
|
||||
|
||||
resolve(component: Type): View {
|
||||
var view = super.resolve(component);
|
||||
var myView = new View({
|
||||
template: MapWrapper.get(this._cache, component),
|
||||
directives: view.directives
|
||||
});
|
||||
var myView =
|
||||
new View({template: MapWrapper.get(this._cache, component), directives: view.directives});
|
||||
return myView;
|
||||
}
|
||||
}
|
||||
@ -172,7 +136,8 @@ class MultipleTemplateResolver extends TemplateResolver {
|
||||
</div>
|
||||
</div>`
|
||||
})
|
||||
class BenchmarkComponentNoBindings {}
|
||||
class BenchmarkComponentNoBindings {
|
||||
}
|
||||
|
||||
@Component()
|
||||
@View({
|
||||
@ -194,4 +159,5 @@ class BenchmarkComponentNoBindings {}
|
||||
</div>
|
||||
</div>`
|
||||
})
|
||||
class BenchmarkComponentWithBindings {}
|
||||
class BenchmarkComponentWithBindings {
|
||||
}
|
@ -12,20 +12,20 @@ export function main() {
|
||||
var fixedMatcher;
|
||||
var fixedSelectorStrings = [];
|
||||
var fixedSelectors = [];
|
||||
for (var i=0; i<count; i++) {
|
||||
for (var i = 0; i < count; i++) {
|
||||
ListWrapper.push(fixedSelectorStrings, randomSelector());
|
||||
}
|
||||
for (var i=0; i<count; i++) {
|
||||
for (var i = 0; i < count; i++) {
|
||||
ListWrapper.push(fixedSelectors, CssSelector.parse(fixedSelectorStrings[i]));
|
||||
}
|
||||
fixedMatcher = new SelectorMatcher();
|
||||
for (var i=0; i<count; i++) {
|
||||
for (var i = 0; i < count; i++) {
|
||||
fixedMatcher.addSelectables(fixedSelectors[i], i);
|
||||
}
|
||||
|
||||
function parse() {
|
||||
var result = [];
|
||||
for (var i=0; i<count; i++) {
|
||||
for (var i = 0; i < count; i++) {
|
||||
ListWrapper.push(result, CssSelector.parse(fixedSelectorStrings[i]));
|
||||
}
|
||||
return result;
|
||||
@ -33,7 +33,7 @@ export function main() {
|
||||
|
||||
function addSelectable() {
|
||||
var matcher = new SelectorMatcher();
|
||||
for (var i=0; i<count; i++) {
|
||||
for (var i = 0; i < count; i++) {
|
||||
matcher.addSelectables(fixedSelectors[i], i);
|
||||
}
|
||||
return matcher;
|
||||
@ -41,10 +41,8 @@ export function main() {
|
||||
|
||||
function match() {
|
||||
var matchCount = 0;
|
||||
for (var i=0; i<count; i++) {
|
||||
fixedMatcher.match(fixedSelectors[i][0], (selector, selected) => {
|
||||
matchCount += selected;
|
||||
});
|
||||
for (var i = 0; i < count; i++) {
|
||||
fixedMatcher.match(fixedSelectors[i][0], (selector, selected) => { matchCount += selected; });
|
||||
}
|
||||
return matchCount;
|
||||
}
|
||||
@ -56,16 +54,16 @@ export function main() {
|
||||
|
||||
function randomSelector() {
|
||||
var res = randomStr(5);
|
||||
for (var i=0; i<3; i++) {
|
||||
res += '.'+randomStr(5);
|
||||
for (var i = 0; i < 3; i++) {
|
||||
res += '.' + randomStr(5);
|
||||
}
|
||||
for (var i=0; i<3; i++) {
|
||||
res += '['+randomStr(3)+'='+randomStr(6)+']';
|
||||
for (var i = 0; i < 3; i++) {
|
||||
res += '[' + randomStr(3) + '=' + randomStr(6) + ']';
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
function randomStr(len){
|
||||
function randomStr(len) {
|
||||
var s = '';
|
||||
while (s.length < len) {
|
||||
s += randomChar();
|
||||
@ -73,11 +71,11 @@ function randomStr(len){
|
||||
return s;
|
||||
}
|
||||
|
||||
function randomChar(){
|
||||
function randomChar() {
|
||||
var n = randomNum(62);
|
||||
if(n<10) return n.toString(); //1-10
|
||||
if(n<36) return StringWrapper.fromCharCode(n+55); //A-Z
|
||||
return StringWrapper.fromCharCode(n+61); //a-z
|
||||
if (n < 10) return n.toString(); // 1-10
|
||||
if (n < 36) return StringWrapper.fromCharCode(n + 55); // A-Z
|
||||
return StringWrapper.fromCharCode(n + 61); // a-z
|
||||
}
|
||||
|
||||
function randomNum(max) {
|
Reference in New Issue
Block a user