OLD | NEW |
1 library di.injector_benchmark_common; | 1 library di.injector_benchmark_common; |
2 | 2 |
3 import 'package:benchmark_harness/benchmark_harness.dart'; | 3 import 'package:benchmark_harness/benchmark_harness.dart'; |
4 import 'package:di/di.dart'; | 4 import 'package:di/di.dart'; |
5 | 5 |
6 int count = 0; | 6 int count = 0; |
7 | 7 |
8 class InjectorBenchmark extends BenchmarkBase { | 8 class InjectorBenchmark extends BenchmarkBase { |
9 var injectorFactory; | 9 var injectorFactory; |
10 var module; | 10 var module; |
11 | 11 |
12 InjectorBenchmark(name, this.injectorFactory) : super(name); | 12 InjectorBenchmark(name, this.injectorFactory) : super(name); |
13 | 13 |
14 void run() { | 14 void run() { |
15 Injector injector = injectorFactory([module]); | 15 Injector injector = injectorFactory([module]); |
16 injector.get(A); | 16 injector.get(A); |
17 injector.get(B); | 17 injector.get(B); |
18 | 18 |
19 var childInjector = injector.createChild([module]); | 19 var childInjector = injector.createChild([module]); |
20 childInjector.get(A); | 20 childInjector.get(A); |
21 childInjector.get(B); | 21 childInjector.get(B); |
22 } | 22 } |
23 | 23 |
24 setup() { | 24 setup() { |
25 module = new Module() | 25 module = new Module() |
26 ..type(A) | 26 ..type(A) |
27 ..type(B) | 27 ..type(B) |
28 ..type(C) | 28 ..type(C) |
| 29 ..type(C, withAnnotation: AnnOne, implementedBy: COne ) |
29 ..type(D) | 30 ..type(D) |
30 ..type(E); | 31 ..type(E) |
| 32 ..type(E, withAnnotation: AnnTwo, implementedBy: ETwo ) |
| 33 ..type(F) |
| 34 ..type(G); |
31 } | 35 } |
32 | 36 |
33 teardown() { | 37 teardown() { |
34 print(count); | 38 print(count); |
35 } | 39 } |
36 } | 40 } |
37 | 41 |
| 42 class AnnOne { |
| 43 const AnnOne(); |
| 44 } |
| 45 |
| 46 class AnnTwo { |
| 47 const AnnTwo(); |
| 48 } |
| 49 |
38 class A { | 50 class A { |
39 A(B b, C c) { | 51 A(B b, C c) { |
40 count++; | 52 count++; |
41 } | 53 } |
42 } | 54 } |
43 | 55 |
44 class B { | 56 class B { |
45 B(D b, E c) { | 57 B(D b, E c) { |
46 count++; | 58 count++; |
47 } | 59 } |
48 } | 60 } |
49 | 61 |
50 class C { | 62 class C { |
51 C() { | 63 C() { |
52 count++; | 64 count++; |
53 } | 65 } |
54 } | 66 } |
55 | 67 |
| 68 class COne { |
| 69 COne() { |
| 70 count++; |
| 71 } |
| 72 } |
| 73 |
56 class D { | 74 class D { |
57 D() { | 75 D() { |
58 count++; | 76 count++; |
59 } | 77 } |
60 } | 78 } |
61 | 79 |
62 class E { | 80 class E { |
63 E() { | 81 E() { |
64 count++; | 82 count++; |
65 } | 83 } |
66 } | 84 } |
| 85 |
| 86 class ETwo { |
| 87 ETwo() { |
| 88 count++; |
| 89 } |
| 90 } |
| 91 |
| 92 class F { |
| 93 F(@AnnOne() C c, D d) { |
| 94 count++; |
| 95 } |
| 96 } |
| 97 |
| 98 class G { |
| 99 G(@AnnTwo() E) { |
| 100 count++; |
| 101 } |
| 102 } |
OLD | NEW |