|
| 1 | +import { |
| 2 | + bootstrap, |
| 3 | + Component, |
| 4 | + Decorator, |
| 5 | + View |
| 6 | +} from 'angular2/angular2'; |
| 7 | +import {LifeCycle} from 'angular2/src/core/life_cycle/life_cycle'; |
| 8 | +import {List, ListWrapper} from 'angular2/src/facade/collection'; |
| 9 | +import {reflector} from 'angular2/src/reflection/reflection'; |
| 10 | +import {ReflectionCapabilities} from 'angular2/src/reflection/reflection_capabilities'; |
| 11 | +import {getIntParameter, bindAction} from 'angular2/src/test_lib/benchmark_util'; |
| 12 | +import {If, For} from 'angular2/directives'; |
| 13 | + |
| 14 | +var testList = null; |
| 15 | + |
| 16 | +export function main() { |
| 17 | + reflector.reflectionCapabilities = new ReflectionCapabilities(); |
| 18 | + var size = getIntParameter('size'); |
| 19 | + testList = ListWrapper.createFixedSize(size); |
| 20 | + |
| 21 | + bootstrap(AppComponent).then((ref) => { |
| 22 | + var injector = ref.injector; |
| 23 | + var app:AppComponent = injector.get(AppComponent); |
| 24 | + var lifeCycle = injector.get(LifeCycle); |
| 25 | + |
| 26 | + bindAction('#reset', function() { |
| 27 | + app.reset(); |
| 28 | + lifeCycle.tick(); |
| 29 | + }); |
| 30 | + |
| 31 | + // Baseline (plain components) |
| 32 | + bindAction('#createPlainComponents', function() { |
| 33 | + app.createPlainComponents(); |
| 34 | + lifeCycle.tick(); |
| 35 | + }); |
| 36 | + |
| 37 | + // Components with decorators |
| 38 | + bindAction('#createComponentsWithDecorators', function() { |
| 39 | + app.createComponentsWithDecorators(); |
| 40 | + lifeCycle.tick(); |
| 41 | + }); |
| 42 | + }); |
| 43 | +} |
| 44 | + |
| 45 | +@Component({selector: 'app'}) |
| 46 | +@View({ |
| 47 | + directives: [If, For, DummyComponent, DummyDecorator], |
| 48 | + template: ` |
| 49 | + <div *if="testingPlainComponents"> |
| 50 | + <dummy *for="#i of list"></dummy> |
| 51 | + </div> |
| 52 | +
|
| 53 | + <div *if="testingWithDecorators"> |
| 54 | + <dummy dummy-decorator *for="#i of list"></dummy> |
| 55 | + </div> |
| 56 | + ` |
| 57 | +}) |
| 58 | +class AppComponent { |
| 59 | + list:List; |
| 60 | + testingPlainComponents:boolean; |
| 61 | + testingWithDecorators:boolean; |
| 62 | + |
| 63 | + constructor() { |
| 64 | + this.reset(); |
| 65 | + } |
| 66 | + |
| 67 | + reset():void { |
| 68 | + this.list = []; |
| 69 | + this.testingPlainComponents = false; |
| 70 | + this.testingWithDecorators = false; |
| 71 | + } |
| 72 | + |
| 73 | + createPlainComponents():void { |
| 74 | + this.list = testList; |
| 75 | + this.testingPlainComponents = true; |
| 76 | + } |
| 77 | + |
| 78 | + createComponentsWithDecorators():void { |
| 79 | + this.list = testList; |
| 80 | + this.testingWithDecorators = true; |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +@Component({selector: 'dummy'}) |
| 85 | +@View({template: `<div></div>`}) |
| 86 | +class DummyComponent {} |
| 87 | + |
| 88 | +@Decorator({selector: '[dummy-decorator]'}) |
| 89 | +class DummyDecorator {} |
0 commit comments