2014-12-22 17:50:10 -08:00
|
|
|
import {Injector, Key} from "di/di";
|
2015-02-02 16:25:34 -08:00
|
|
|
import {reflector} from 'reflection/src/reflection';
|
|
|
|
|
import {getIntParameter, bindAction} from 'e2e_test_lib/src/benchmark_util';
|
2014-12-22 17:50:10 -08:00
|
|
|
|
|
|
|
|
var count = 0;
|
|
|
|
|
|
|
|
|
|
function setupReflector() {
|
|
|
|
|
reflector.registerType(A, {
|
|
|
|
|
'factory': () => new A(),
|
|
|
|
|
'parameters': [],
|
|
|
|
|
'annotations' : []
|
|
|
|
|
});
|
|
|
|
|
reflector.registerType(B, {
|
|
|
|
|
'factory': (a) => new B(a),
|
|
|
|
|
'parameters': [[A]],
|
|
|
|
|
'annotations' : []
|
|
|
|
|
});
|
|
|
|
|
reflector.registerType(C, {
|
|
|
|
|
'factory': (b) => new C(b),
|
|
|
|
|
'parameters': [[B]],
|
|
|
|
|
'annotations' : []
|
|
|
|
|
});
|
|
|
|
|
reflector.registerType(D, {
|
|
|
|
|
'factory': (c,b) => new D(c,b),
|
|
|
|
|
'parameters': [[C],[B]],
|
|
|
|
|
'annotations' : []
|
|
|
|
|
});
|
|
|
|
|
reflector.registerType(E, {
|
|
|
|
|
'factory': (d,c) => new E(d,c),
|
|
|
|
|
'parameters': [[D],[C]],
|
|
|
|
|
'annotations' : []
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function main() {
|
2015-01-09 18:00:04 -08:00
|
|
|
var iterations = getIntParameter('iterations');
|
|
|
|
|
|
2014-12-22 17:50:10 -08:00
|
|
|
setupReflector();
|
|
|
|
|
var bindings = [A, B, C, D, E];
|
|
|
|
|
var injector = new Injector(bindings);
|
|
|
|
|
|
|
|
|
|
var D_KEY = Key.get(D);
|
|
|
|
|
var E_KEY = Key.get(E);
|
|
|
|
|
var childInjector = injector.
|
|
|
|
|
createChild([]).
|
|
|
|
|
createChild([]).
|
|
|
|
|
createChild([]).
|
|
|
|
|
createChild([]).
|
|
|
|
|
createChild([]);
|
|
|
|
|
|
2015-01-09 18:00:04 -08:00
|
|
|
function getByToken () {
|
|
|
|
|
for (var i = 0; i < iterations; ++i) {
|
2014-12-22 17:50:10 -08:00
|
|
|
injector.get(D);
|
|
|
|
|
injector.get(E);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-01-09 18:00:04 -08:00
|
|
|
function getByKey() {
|
|
|
|
|
for (var i = 0; i < iterations; ++i) {
|
2014-12-22 17:50:10 -08:00
|
|
|
injector.get(D_KEY);
|
|
|
|
|
injector.get(E_KEY);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-09 18:00:04 -08:00
|
|
|
function getChild () {
|
|
|
|
|
for (var i = 0; i < iterations; ++i) {
|
2014-12-22 17:50:10 -08:00
|
|
|
childInjector.get(D);
|
|
|
|
|
childInjector.get(E);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-09 18:00:04 -08:00
|
|
|
function instantiate () {
|
|
|
|
|
for (var i = 0; i < iterations; ++i) {
|
2014-12-22 17:50:10 -08:00
|
|
|
var child = injector.createChild([E]);
|
|
|
|
|
child.get(E);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-09 18:00:04 -08:00
|
|
|
bindAction('#getByToken', getByToken);
|
|
|
|
|
bindAction('#getByKey', getByKey);
|
|
|
|
|
bindAction('#getChild', getChild);
|
|
|
|
|
bindAction('#instantiate', instantiate);
|
2014-12-22 17:50:10 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class A {
|
|
|
|
|
constructor() {
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class B {
|
|
|
|
|
constructor(a:A) {
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class C {
|
|
|
|
|
constructor(b:B) {
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class D {
|
|
|
|
|
constructor(c:C, b:B) {
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class E {
|
|
|
|
|
constructor(d:D, c:C) {
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
}
|