perf(benchmark): measure Injector init from resolved bindings

This commit is contained in:
Yegor Jbanov 2015-04-11 14:19:20 -07:00
parent 4a961f4ecb
commit c05bad381c
3 changed files with 34 additions and 1 deletions

View File

@ -80,4 +80,21 @@ describe('ng2 di benchmark', function () {
}).then(done, done.fail);
});
/**
* Same as 'createVariety' benchmark but operates on fully resolved bindings.
*/
it('should log the stats for createVarietyResolved', function(done) {
perfUtil.runClickBenchmark({
url: URL,
buttons: ['#createVarietyResolved'],
id: 'ng2.di.createVarietyResolved',
params: [{
name: 'iterations', value: 10000, scale: 'linear'
}],
microMetrics: {
'injectAvg': 'avg time for createVarietyResolved (in ms)'
}
}).then(done, done.fail);
});
});

View File

@ -17,6 +17,7 @@
<button id="getChild">getChild</button>
<button id="instantiate">instantiate</button>
<button id="createVariety">createVariety</button>
<button id="createVarietyResolved">createVarietyResolved</button>
</div>
$SCRIPTS$

View File

@ -34,6 +34,8 @@ export function main() {
bind(F).toValue(6)
];
var variousBindingsResolved = Injector.resolve(variousBindings);
function getByToken() {
for (var i = 0; i < iterations; ++i) {
injector.get(D);
@ -66,7 +68,16 @@ export function main() {
*/
function createVariety() {
for (var i = 0; i < iterations; ++i) {
new Injector(variousBindings);
Injector.resolveAndCreate(variousBindings);
}
}
/**
* Same as [createVariety] but resolves bindings ahead of time.
*/
function createVarietyResolved() {
for (var i = 0; i < iterations; ++i) {
Injector.fromResolvedBindings(variousBindingsResolved);
}
}
@ -90,6 +101,10 @@ export function main() {
'#createVariety',
() => microBenchmark('injectAvg', iterations, createVariety)
);
bindAction(
'#createVarietyResolved',
() => microBenchmark('injectAvg', iterations, createVarietyResolved)
);
}