perf(benchmark): measure Injector init from resolved bindings
This commit is contained in:
parent
4a961f4ecb
commit
c05bad381c
|
@ -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);
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -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$
|
||||
|
|
|
@ -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)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue