Skip to content

Commit

Permalink
perf(benchmarks): benchmark that measure cost of dynamic components
Browse files Browse the repository at this point in the history
  • Loading branch information
yjbanov committed Apr 27, 2015
1 parent 9fc9d53 commit 427f0d0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
17 changes: 15 additions & 2 deletions modules/benchmarks/e2e_test/costs_perf.es6
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ var perfUtil = require('angular2/src/test_lib/perf_util');
describe('ng2 cost benchmark', function () {

var URL = 'benchmarks/src/costs/index.html';

// Number of components to create in a single iteration
var benchmarkSize = 200;

afterEach(perfUtil.verifyNoBrowserErrors);
Expand All @@ -13,7 +15,7 @@ describe('ng2 cost benchmark', function () {
buttons: ['#reset', '#createPlainComponents'],
id: 'ng2.costs.baseline',
params: [{
name: 'size', value: 200, scale: 'linear'
name: 'size', value: benchmarkSize, scale: 'linear'
}]
}).then(done, done.fail);
});
Expand All @@ -24,7 +26,18 @@ describe('ng2 cost benchmark', function () {
buttons: ['#reset', '#createComponentsWithDecorators'],
id: 'ng2.costs.decorators',
params: [{
name: 'size', value: 200, scale: 'linear'
name: 'size', value: benchmarkSize, scale: 'linear'
}]
}).then(done, done.fail);
});

it('should log stats for dynamic components', function(done) {
perfUtil.runClickBenchmark({
url: URL,
buttons: ['#reset', '#createDynamicComponents'],
id: 'ng2.costs.dynamic',
params: [{
name: 'size', value: benchmarkSize, scale: 'linear'
}]
}).then(done, done.fail);
});
Expand Down
4 changes: 4 additions & 0 deletions modules/benchmarks/src/costs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ <h2>Benchmarks</h2>
<td>Cost of decorators</td>
<td><button id="createComponentsWithDecorators">Run</button></td>
</tr>
<tr>
<td>Cost of dynamic components</td>
<td><button id="createDynamicComponents">Run</button></td>
</tr>
</table>

<app></app>
Expand Down
31 changes: 29 additions & 2 deletions modules/benchmarks/src/costs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import {
bootstrap,
Component,
Decorator,
View
View,
DynamicComponentLoader,
ElementRef,
DynamicComponent
} from 'angular2/angular2';
import {LifeCycle} from 'angular2/src/core/life_cycle/life_cycle';
import {List, ListWrapper} from 'angular2/src/facade/collection';
Expand Down Expand Up @@ -39,12 +42,18 @@ export function main() {
app.createComponentsWithDecorators();
lifeCycle.tick();
});

// Components with decorators
bindAction('#createDynamicComponents', function() {
app.createDynamicComponents();
lifeCycle.tick();
});
});
}

@Component({selector: 'app'})
@View({
directives: [If, For, DummyComponent, DummyDecorator],
directives: [If, For, DummyComponent, DummyDecorator, DynamicDummy],
template: `
<div *if="testingPlainComponents">
<dummy *for="#i of list"></dummy>
Expand All @@ -53,12 +62,17 @@ export function main() {
<div *if="testingWithDecorators">
<dummy dummy-decorator *for="#i of list"></dummy>
</div>
<div *if="testingDynamicComponents">
<dynamic-dummy *for="#i of list"></dynamic-dummy>
</div>
`
})
class AppComponent {
list:List;
testingPlainComponents:boolean;
testingWithDecorators:boolean;
testingDynamicComponents:boolean;

constructor() {
this.reset();
Expand All @@ -68,6 +82,7 @@ class AppComponent {
this.list = [];
this.testingPlainComponents = false;
this.testingWithDecorators = false;
this.testingDynamicComponents = false;
}

createPlainComponents():void {
Expand All @@ -79,6 +94,11 @@ class AppComponent {
this.list = testList;
this.testingWithDecorators = true;
}

createDynamicComponents():void {
this.list = testList;
this.testingDynamicComponents = true;
}
}

@Component({selector: 'dummy'})
Expand All @@ -87,3 +107,10 @@ class DummyComponent {}

@Decorator({selector: '[dummy-decorator]'})
class DummyDecorator {}

@DynamicComponent({selector: 'dynamic-dummy'})
class DynamicDummy {
constructor(loader:DynamicComponentLoader, location:ElementRef) {
loader.loadIntoExistingLocation(DummyComponent, location);
}
}

0 comments on commit 427f0d0

Please sign in to comment.