1- import { Injectable , Injector , Key } from "angular2/di" ;
1+ import { Injectable , Injector , Key , bind } from "angular2/di" ;
22import { reflector } from 'angular2/src/reflection/reflection' ;
33import { ReflectionCapabilities } from 'angular2/src/reflection/reflection_capabilities' ;
44import { getIntParameter , bindAction , microBenchmark } from 'angular2/src/test_lib/benchmark_util' ;
@@ -27,7 +27,14 @@ export function main() {
2727 createChild ( [ ] ) .
2828 createChild ( [ ] ) ;
2929
30- function getByToken ( ) {
30+ var variousBindings = [
31+ A ,
32+ bind ( B ) . toClass ( C ) ,
33+ [ D , [ E ] ] ,
34+ bind ( F ) . toValue ( 6 )
35+ ] ;
36+
37+ function getByToken ( ) {
3138 for ( var i = 0 ; i < iterations ; ++ i ) {
3239 injector . get ( D ) ;
3340 injector . get ( E ) ;
@@ -40,20 +47,29 @@ export function main() {
4047 }
4148 }
4249
43- function getChild ( ) {
50+ function getChild ( ) {
4451 for ( var i = 0 ; i < iterations ; ++ i ) {
4552 childInjector . get ( D ) ;
4653 childInjector . get ( E ) ;
4754 }
4855 }
4956
50- function instantiate ( ) {
57+ function instantiate ( ) {
5158 for ( var i = 0 ; i < iterations ; ++ i ) {
5259 var child = injector . createChild ( [ E ] ) ;
5360 child . get ( E ) ;
5461 }
5562 }
5663
64+ /**
65+ * Creates an injector with a variety of binding types.
66+ */
67+ function createVariety ( ) {
68+ for ( var i = 0 ; i < iterations ; ++ i ) {
69+ new Injector ( variousBindings ) ;
70+ }
71+ }
72+
5773 bindAction (
5874 '#getByToken' ,
5975 ( ) => microBenchmark ( 'injectAvg' , iterations , getByToken )
@@ -70,6 +86,10 @@ export function main() {
7086 '#instantiate' ,
7187 ( ) => microBenchmark ( 'injectAvg' , iterations , instantiate )
7288 ) ;
89+ bindAction (
90+ '#createVariety' ,
91+ ( ) => microBenchmark ( 'injectAvg' , iterations , createVariety )
92+ ) ;
7393}
7494
7595
@@ -108,3 +128,10 @@ class E {
108128 count ++ ;
109129 }
110130}
131+
132+ @Injectable ( )
133+ class F {
134+ constructor ( e :E , d :D ) {
135+ count ++ ;
136+ }
137+ }
0 commit comments