Document directory
- The contestants
- The test setup
- Overview
- Singleton
- Transient
- Combined
Announcements
This arctile is posted by Daniel Palme, who is. net consultant from Germany. I found it in his blog, and it's very helpful to me. so I decide to post it in my cnblogs. as it is so simple, as well as I 've been used to read English articles. so I decided not to translate it into Chinese to keep the original meaning. you can click this link to access the original.
In this post I will do a performance comparison of the most popular IOC containers.
Of course performance is not the only criteria when choosing a container for a project. perhaps you need features like interception, then not all containers are suited. but if the container is "only" used for wiring up dependencies, Why not choose the fastest one?
The test setupthe contestants
- Autofac
- Caliburn. Micro
- Catel
- Dynamo. IOC
- Funq
- Griffin in
- Hiro
- Lightcore
- Lightinject
- Linfu
- MEF
- Microsliver
- Mugen
- Munq
- Ninject
- Petite
- Simple Injector
- Speedioc
- Spring. net
- Structuremap
- Tinyioc
- Unity
- Windsor
You probably have heard of most of the frameworks, but one of them is quite new and works differently: Hiro the author, Philip Laurel ano, names it an "inversion of control container compiler framework ". after configuration, the container gets compiled and is immutable from now on. this concept makes this container really fast.
The test setup
To test the performance I register three interfaces and their corresponding implementation to every container. the first one is registered as a Singleton, the second one as transient (a new instance is created every time ). the third also has a transient lifetime, but moreover has a dependency to the first two interfaces (which get injected by constructor injection ).
Every interface is resolved 1.000.000 times and the time is measured in milliseconds.
The resultsoverview
Container |
Singleton |
Transient |
Combined |
Interception |
No |
132 |
81 |
63 |
|
Autofac 3.0.2 |
749 |
1806 |
4570 |
33765 |
Caliburn. Micro 1.5.1 |
194 |
226 |
651 |
|
Catel 3.5 |
258 |
952 |
2846 |
|
Dynamo 3.0.1.0 |
72 |
84 |
139 |
|
Funq 1.0.0.0 |
81 |
92 |
277 |
|
Griffin in 1.1.0 |
194 |
195 |
481 |
|
Hiro 1.0.3 |
101 |
103 |
107 |
|
Lightcore 1.5.1 |
156 |
2343 |
12045 |
|
Lightinject 3.0.0.5 |
171 |
178 |
298 |
|
Linfu 2.3.0.20.59 |
2876 |
17564 |
47712 |
|
MEF 4.0.0.0 |
2507 |
8724 |
24937 |
|
Microsliver 2.1.6.0 |
150 |
485 |
2019 |
|
Mugen 3.5.1 |
302 |
483 |
1404 |
|
Munq 3.1.6 |
102 |
131 |
412 |
|
Ninject 3.0.1.10 |
6791 |
19314 |
54926 |
|
Petite 0.3.2 |
86 |
86 |
260 |
|
Simpleinjector 2.2.3 |
68 |
87 |
101 |
467 |
Speedioc 0.1.33 |
96 |
109 |
94 |
|
Spring. Net 1.3.2 |
672 |
14560 |
39065 |
666 |
Structuremap 2.6.4.1 |
1127 |
1213 |
4379 |
7329 |
Tinyios 1.2 |
246 |
1500 |
6098 |
|
Unity 3.0.1304.0 |
2451 |
3807 |
11212 |
103682 |
Windsor 3.2.0 |
456 |
2422 |
6970 |
16677 |
Singleton
Transient
Combined
Feature comparison
|
Performance |
Configuration |
Features |
Environment |
Container |
|
Code |
XML |
Auto |
Autowiring |
Custom lifetimes |
Interception |
. Net |
SL |
WP7 |
Winrt |
Autofac |
Average |
Yes |
Yes |
Yes |
Yes |
No |
Yes |
Yes |
Yes |
Yes |
Yes |
Caliburn. Micro |
Average |
No |
No |
No |
Yes |
No |
No |
Yes |
Yes |
Yes |
Yes |
Catel |
Average |
Yes |
No |
No |
Yes |
Yes |
No |
Yes |
Yes |
Yes |
Yes |
Dynamo |
Fast |
Yes |
No |
Yes |
Yes |
Yes |
No |
Yes |
No |
No |
No |
Funq |
Fast |
Yes |
No |
No |
No |
No |
No |
Yes |
Yes |
Yes |
No |
Griffin in |
Fast |
Yes |
No |
No |
Yes |
No |
Yes |
Yes |
No |
No |
No |
Hiro |
Fast |
Yes |
No |
No |
Yes |
No |
No |
Yes |
No |
No |
No |
Lightcore |
Average |
Yes |
Yes |
Yes |
Yes |
Yes |
No |
Yes |
Yes |
No |
No |
Lightinject |
Fast |
Yes |
No |
Yes |
No |
Yes |
No |
Yes |
Yes |
No |
No |
Linfu |
Slow |
Yes |
No |
No |
Yes |
No |
Yes |
Yes |
No |
No |
No |
MEF |
Slow |
Yes |
No |
No |
Yes |
No |
No |
Yes |
Yes |
No |
Yes |
Microsliver |
Average |
Yes |
No |
No |
Yes |
No |
No |
Yes |
Yes |
No |
Yes |
Mugen |
Average |
Yes |
No |
No |
Yes |
Yes |
No |
Yes |
Yes |
Yes |
Yes |
Munq |
Fast |
Yes |
No |
No |
Yes |
Yes |
No |
Yes |
No |
Yes |
No |
Ninject |
Slow |
Yes |
No |
Yes |
Yes |
Yes |
No |
Yes |
Yes |
Yes |
Yes |
Petite |
Fast |
Yes |
No |
No |
No |
No |
No |
Yes |
No |
No |
No |
Simpleinjector |
Fast |
Yes |
No |
Yes |
Yes |
Yes |
Yes |
Yes |
Yes |
No |
No |
Speedioc |
Fast |
Yes |
No |
No |
No |
No |
No |
Yes |
No |
No |
No |
Spring. net |
Very slow |
No |
Yes |
No |
Yes |
No |
Yes |
Yes |
No |
No |
No |
Structuremap |
Average |
Yes |
Yes |
Yes |
Yes |
Yes |
Yes |
Yes |
No |
Yes |
No |
Tinyioc |
Average |
Yes |
No |
Yes |
Yes |
Yes |
No |
Yes |
Yes |
Yes |
No |
Unity |
Average |
Yes |
Yes |
No |
Yes |
Yes |
Yes |
Yes |
Yes |
No |
Yes |
Windsor |
Average |
Yes |
Yes |
Yes |
Yes |
Yes |
Yes |
Yes |
Yes |
No |
No |
Conclusion
Ninject is definitely the slowest container.
MEF, linfu and spring. net are faster than ninject, but still pretty slow. autofac, catel and Windsor come next, followed by structuremap, unity and lightcore. A disadvantage of spring. net is, that can only be configured with XML.
Simpleinjector, Hiro, funq, munq and Dynamo offer the best performance, they are extremely fast. Give them a try! Especially simple injector seems to be a good choice. It's very fast, has a good documentation and also supports advanced scenarios like interception and generic decorators.
Updates
13.09.2011: funq and munq have been added to the list of contestants, both frameworks are really fast. The updated charts do no more contain spring. net, since it was extremly slow.
04.11.2011: I added simple injector, the performance is the best of all contestants.
16.12.2011: I added dynamo. IOC, the performance is very close to simple injector and Hiro.
22.01.2012: added tinyioc.
22.02.2012: UpdatedIservicelocatorImplementations.
12.03.2012: added lightinject. added feature comparison.
25.04.2012: Updated to ninject 3.0.015 and petite 0.3.2.
14.05.2012: added Mugen.
14.06.2012: added MEF.
18.06.2012: added Griffin in.
2018.8.2012: Updated to Castle Windsor 3.1.0, lightinject 2.0.0.0, simple injector 1.5.0.12199, structuremap 2.6.4.1, mugeninjection 2.6.0 and unity 2.1.505.2
18.09.2012: added catel.
15.10.2012: Updated to dynamo. IOC 3.0.1.0 and mugeninjection 3.0.0
15.12.2012: Updated to catel 3.4, Griffin. Container 1.1.0, simpleinjector 1.6.0.12319, tinyioc 1.2
01.01.2013: added Caliburn. Micro 1.4
06.01.2013: added speedioc. Updated to autofac 3.0.0, Caliburn. Micro. Container 1.4.1, lightcore 1.5.0
262.162.2013: Updated to autofac 3.0.1, lightcore 1.5.1, Windsor 3.2.0
15.03.2013: added benchmark for interception
03.04.2013: added microsliver
11.04.2013: updated several containers
09.05.2013: Updated lightinject, simpleinjector and unity
Source code
Latest source code is available on GitHub.
Downloads
Iocperformance.7z