This project benchmark the following DI solutions:
- Vanilla
- Guice - 4.1.0
- Genie - 0.2.0-SNAPSHOT
- Feather - 1.0
- Dagger - 1.2.5
- Pico - 2.15
- jBeanBox - 2.4.9
- Spring - 4.3.2.RELEASE
Below is the object graph of the class to be injected in the benchmark program
Object
└── A
└── B
└── C
├── D1
└── D2
└── E
All injection is done through Constructor injection
Split Starting up DI containers & instantiating a dependency graph 4999 times:
-------------------------------------------------------------------------------
Vanilla| start: 0ms fetch: 0ms
Guice| start: 1046ms fetch: 1560ms
Feather| start: 0ms fetch: 109ms
Dagger| start: 46ms fetch: 173ms
Pico| start: 376ms fetch: 217ms
Genie| start: 766ms fetch: 247ms
jBeanBoxNormal| start: 79ms fetch: 982ms
jBeanBoxTypeSafe| start: 0ms fetch: 998ms
jBeanBoxAnnotation| start: 0ms fetch: 468ms
SpringJavaConfiguration| start: 51831ms fetch: 1834ms
SpringAnnotationScanned| start: 70712ms fetch: 4155ms
Runtime benchmark, fetch new bean for 500000 times:
---------------------------------------------------------
Vanilla| 31ms
Guice| 1154ms
Feather| 624ms
Dagger| 312ms
Genie| 609ms
Pico| 4555ms
jBeanBoxNormal| 2075ms
jBeanBoxTypeSafe| 2371ms
jBeanBoxAnnotation| 2059ms
SpringJavaConfiguration| 92149ms
SpringAnnotationScanned| 95504ms
Runtime benchmark, fetch singleton bean for 5000000 times:
---------------------------------------------------------
Vanilla| 47ms
Guice| 1950ms
Feather| 624ms
Dagger| 2746ms
Genie| 327ms
Pico| 3385ms
jBeanBoxNormal| 188ms
jBeanBoxTypeSafe| 187ms
jBeanBoxAnnotation| 171ms
SpringJavaConfiguration| 1061ms
SpringAnnotationScanned| 1045ms
You need JDK8 and maven to run the benchmark program.
The project defined two profiles: runtime
and split_startup
.
#Run the `runtime` profile:
mvn clean compile exec:exec -Pruntime
This will run the Runtime benchmark, which fetch the bean of class A
(as shown above) for 50K
times
#To run the `split_startup` profile:
mvn clean compile exec:exec -Psplit_startup
This will run the startup benchmark, which initialize the injector and load bean of class A
for 5K
times.
To tune the warm up and iterations:
#For startup benchmark:
mvn clean compile exec:exec -Psplit_startup -Dstartup.iteration=100 -Dstartup.warmup=10
#For runtime benchmark:
mvn clean compile exec:exec -Pruntime -Druntime.iteration=1000 -Druntime.warmup=100
To benchmark singleton injection:
mvn clean compile exec:exec -Pruntime -Dsingleton=true
The benchmark source code is originated from https://github.com/zsoltherpai/feather/tree/master/performance-test and adapted by Gelin Luo