Sitecore in-built DI's Performance Drill!
Introduction
This article shows a short comparison between Microsoft.Extensions.DependencyInjection and some other popular dependency injection's performance. Although performance should not be the only reason for choosing a particular container.
Disclaimer
- This performance test does not cover all features of all containers but only uses a few types.
- The results might change according to the number of types configured
- This is just a basic performance test for the main purpose of comparing Sitecore DI container's basic performance to a few selected full-featured DI containers (Unity, Ninject and SimpleInjector).
- The performance tool was initially built by @DanielPalme but I slightly modified it to integrate some changes. This is the github repository link
Results
1. Explanations
First value: Time of single-threaded execution in [ms]
Second value: Time of multi-threaded execution in [ms]
*: Benchmark was stopped after 1 minute and result is extrapolated.
2. BASIC FEATURES
Container | Singleton(ms) | Transient(ms) | Combined(ms) | Complex(ms) |
---|---|---|---|---|
No | 87 227 |
149 259 |
159 219 |
299 233 |
SimpleInjector 4.0.12 | 72 135 |
111 133 |
173 175 |
263 199 |
Microsoft Extensions DependencyInjection 1.0.0 | 290 363 |
234 248 |
495 478 |
1154 1244 |
Ninject 3.3.3 | 3114 2617 |
9486 8365 |
30243 21713 |
85698 61883 |
Unity 5.1.2 | 4176 2373 |
5352 3294 |
14886 8038 |
41618 25101 |
3. ADVANCED FEATURES
Container | Property(ms) | Generics(ms) | IEnumerable(ms) | Conditional(ms) | Child Container(ms) | Asp Net Core(ms) | Interception With Proxy(ms) |
---|---|---|---|---|---|---|---|
No | 291 243 |
96 148 |
353 269 |
111 147 |
805 540 |
110 141 |
|
SimpleInjector 4.0.12 | 350 276 |
163 190 |
858 552 |
203 211 |
457265* 11523032* |
||
Microsoft Extensions DependencyInjection 1.0.0 | 291 253 |
977 656 |
1757 1938 |
||||
Ninject 3.3.3 | 85524* 58351 |
31091 17873 |
67464* 46840 |
19594 14549 |
131433000 166175824 |
535767 11363928 |
|
Unity 5.1.2 | 40694 24990 |
56885 31426 |
36079 21251 |
670988 9414810 |
4. PREPARE
Container | Prepare And Register(ms) | Prepare And Register And Simple Resolve(ms) |
---|---|---|
No | 3 |
5 |
SimpleInjector 4.0.12 | 2824 |
7605 |
Microsoft Extensions DependencyInjection 1.0.0 | 26 |
29 |
Ninject 3.3.3 | 265986* |
259215* |
Unity 5.1.2 | 112 |
1527 |
Conclusion
As you might have noticed, in this particular test scope:
- SimpleInjector comes on top when it comes to basic and advanced features.
- Sitecore's DI does not support certain features hence, could not be compared with a more full feature DI framework.
- When it comes to perpare, register and simple resolve, Sitecore's DI comes on top.
Performance is not the only criteria that needs to be taken into consideration when choosing a particular container, although in a web application, when handling multiple request, spread on multiple servers (maybe) you might heavily consider performance.
If your web application does not require and make a slightly use of a more full-featured DI Container, I would suggest you to plan your move your move to use Sitecore in-built DI container.
Machine
The benchmark was executed on the following machine:
CPU: Intel(R) Core(TM) i5-7300U CPU @ 2.60GHz
Memory: 15,89GB
The source code of this performance tool can be found on github