| 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; | |
| 7 | |
| 8 class InjectorBenchmark extends BenchmarkBase { | 6 class InjectorBenchmark extends BenchmarkBase { |
| 9 var injectorFactory; | 7 var injectorFactory; |
| 10 var module; | 8 var module; |
| 11 | 9 |
| 12 InjectorBenchmark(name, this.injectorFactory) : super(name); | 10 InjectorBenchmark(name, this.injectorFactory) : super(name); |
| 13 | 11 |
| 14 void run() { | 12 void run() { |
| 15 Injector injector = injectorFactory([module]); | 13 Injector injector = injectorFactory([module]); |
| 16 injector.get(A); | 14 injector.get(A); |
| 17 injector.get(B); | 15 injector.get(B); |
| 18 | 16 |
| 19 var childInjector = injector.createChild([module]); | 17 var childInjector = injector.createChild([module]); |
| 20 childInjector.get(A); | 18 childInjector.get(A); |
| 21 childInjector.get(B); | 19 childInjector.get(B); |
| 22 } | 20 } |
| 23 | 21 |
| 24 setup() { | 22 setup() { |
| 25 module = new Module() | 23 module = new Module() |
| 26 ..type(A) | 24 ..type(A) |
| 27 ..type(B) | 25 ..type(B) |
| 28 ..type(C) | 26 ..type(C) |
| 29 ..type(D) | 27 ..type(D) |
| 30 ..type(E); | 28 ..type(E); |
| 31 } | 29 } |
| 32 | |
| 33 teardown() { | |
| 34 print(count); | |
| 35 } | |
| 36 } | 30 } |
| 37 | 31 |
| 38 class A { | 32 class A { |
| 39 A(B b, C c) { | 33 A(B b, C c); |
| 40 count++; | |
| 41 } | |
| 42 } | 34 } |
| 43 | 35 |
| 44 class B { | 36 class B { |
| 45 B(D b, E c) { | 37 B(D b, E c); |
| 46 count++; | |
| 47 } | |
| 48 } | 38 } |
| 49 | 39 |
| 50 class C { | 40 class C { |
| 51 C() { | |
| 52 count++; | |
| 53 } | |
| 54 } | 41 } |
| 55 | 42 |
| 56 class D { | 43 class D { |
| 57 D() { | |
| 58 count++; | |
| 59 } | |
| 60 } | 44 } |
| 61 | 45 |
| 62 class E { | 46 class E { |
| 63 E() { | |
| 64 count++; | |
| 65 } | |
| 66 } | 47 } |
| OLD | NEW |