IoC Container Benchmark - Performance comparison

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 or you develop for a specific platform, then not all containers are suited. But especially in high-load scenarios like a web application, a fast container can help you to serve more requests in the same time, so why not choose the fastest one?

The test setup

The contestants

The number of available DI containers is quite big (see table below). Some of the mature frameworks like Ninject or Unity are widly used but are pretty slow.
Most of the younger containers offer a better performance. Internally most of them use compiled expressions to improve the resolve times.

The test setup

Several benchmarks are executed to test the performance of the containers in different scenarios. Every container is initialized with a couple of interfaces and their corresponding implementations. The types are registered with different lifetimes to support the various benchmarks.

Every interface is resolved 500.000 times during the benchmark and the time is measured in milliseconds.

The benchmarks:

  • Singleton: Objects with is singleton lifetime are resolved
  • Transient: Objects with is transient lifetime are resolved
  • Combined: Objects with two dependencies (singleton and transient lifetime) are resolved
  • Complex: Objects with several nested dependencies are resolved
  • Property: Objects which require property injection are resolved
  • Generics: Objects with a generic dependency are resolved
  • IEnumerable: Several objects that implement the same interface are resolved
  • Conditional: Objects with a conditional dependency are resolved
  • Child Container: Objects are resolved trough a child container
  • Interception With Proxy: Objects with a dynamically generated wrapper are resolved

 

The results

Overview

Container Singleton Transient Combined Complex Property Generics IEnumerable Conditional Child Container Interception With Proxy
No 115 94 102 127 124 98 266 86 690 79
Autofac 3.3.1 826 2132 5659 16112 34668 4882 17360   110250 45333
Caliburn.Micro 1.5.2 474 566 1664 7402 9670   7156      
Catel 3.9.0 372 4498 13350 33606   12697       4384
DryIoc 1.2.0 53 77 82 101 131 69 354 66    
Dynamo 3.0.2.0 108 140 216 791 913          
fFastInjector 0.8.1 98 129 164 271            
Funq 1.0.0.0 158 186 423 1271 1211          
Grace 2.2.4 203 358 770 2027 2365 618 2945 847 20343 11979
Griffin 1.1.1 269 261 709 2026            
HaveBox 2.0.0 78 86 95 151 1025   2177     883
Hiro 1.0.4.41795 196 195 208 263 3013          
IfInjector 0.8.1 99 152 175 231 422 167        
LightCore 1.5.1 190 3000 36503 215898 2474 25055 52115      
LightInject 3.0.1.6 51 71 74 121 115 87 355 65   1568
LinFu 2.3.0.41559 4067 26467 66663 184134            
Maestro 1.4.0 298 400 1115 3413 4259 729 4201 1009   9621
Mef 4.0.0.0 33062 50433 80331 156652 165820 186915 117780      
Mef2 1.0.20.0 322 301 364 596 1474 312 1657      
MicroSliver 2.1.6.0 252 787 2781 7985            
Mugen 3.5.1 482 836 2283 8461 14046 70232 6643 1805 676980 17034
Munq 3.1.6 108 143 502 1862 1648          
Ninject 3.2.2.0 6492 24272 62890 175626 168957 72105 161954 54132 42893400  
Petite 0.3.2 5584 4980 5612 6129 6995          
SimpleInjector 2.5.0 85 109 123 169 227 109 853 228   13380
Spring.NET 1.3.2 1063 16794 44736 114565 104652         75437
StructureMap 3.0.3.116 2723 2600 8337 21074 20704 5681 16323   3426075 13094
StyleMVVM 3.1.5 535 574 854 1696 1792 2914 3828 2830    
TinyIoC 1.2 400 2555 10215 45779 4346       16900  
Unity 3.5.1404.0 2895 4361 11498 33770 36882   62250   50091 129511
Windsor 3.2.1 497 2775 8664 24363 52963 24487 24169   376329 32812

Basic features

IocPerformance - Basic features

Advanced features

IocPerformance - Advanced features

Feature comparison

  Performance Configuration Features Environment
Container   Code XML Auto Autowiring Custom lifetimes Interception .NET SL WP7 WP8 WinRT
AutoFac Average Yes Yes Yes Yes No Yes Yes Yes Yes Yes Yes
Caliburn.Micro Average No No No Yes No No Yes Yes Yes Yes Yes
Catel Average Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes
DryIoc Fast Yes No No Yes Yes No Yes No No No No
Dynamo Fast Yes No Yes Yes Yes No Yes No No No No
fFastInjector Fast Yes No No Yes No No Yes Yes Yes No Yes
Funq Fast Yes No No No No No Yes Yes Yes No No
Grace Average Yes Yes Yes Yes Yes Yes Yes No No Yes Yes
Griffin Fast Yes No No Yes No Yes Yes No No No No
HaveBox Fast Yes No No Yes No Yes Yes Yes Yes Yes No
Hiro Fast Yes No No Yes No No Yes No No No No
IfInjector Fast Yes No No Yes No No Yes Yes Yes No Yes
LightCore Average Yes Yes Yes Yes Yes No Yes Yes No No No
LightInject Fast Yes No Yes Yes Yes Yes Yes Yes No Yes Yes
LinFu Slow Yes No No Yes No Yes Yes No No No No
Maestro Average Yes No No Yes Yes Yes Yes Yes Yes Yes Yes
MEF Slow Yes No No Yes No No Yes Yes No No Yes
MEF2 Fast Yes No No Yes No No Yes No Yes Yes Yes
MicroSliver Average Yes No No Yes No No Yes Yes No No Yes
Mugen Average Yes No No Yes Yes Yes Yes Yes Yes Yes Yes
Munq Fast Yes No No Yes Yes No Yes No Yes No No
Ninject Slow Yes Yes Yes Yes Yes No Yes Yes Yes No Yes
Petite Fast Yes No No No No No Yes No No No No
SimpleInjector Fast Yes No Yes Yes Yes Yes Yes Yes No Yes Yes
Speedioc Fast Yes No No No No No Yes No No No No
Spring.NET Very slow No Yes No Yes No Yes Yes No No No No
Stiletto Average Yes No No Yes No No Yes Yes Yes Yes No
StructureMap Average Yes Yes Yes Yes Yes Yes Yes No Yes No Yes
StyleMVVM Fast Yes No Yes Yes Yes No Yes No No Yes No
TinyIoc Average Yes No No Yes Yes No Yes Yes Yes No No
Unity Average Yes Yes Yes Yes Yes Yes Yes Yes No Yes Yes
Windsor Average Yes Yes Yes Yes Yes Yes Yes Yes No 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.

DryIoc, LightInject and SimpleInjector offer a very performance combined with support for advanced scenarios like interception and generic decorators.
Simple Injector and LightInject also provide extensive documentation and support all important platforms.

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: Updated IServiceLocator implementations.

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.

20.08.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

26.02.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

02.06.2013: Added fFastInjector and HaveBox. Updated Dynamo.IOC

16.06.2013: Updated HaveBox.

16.06.2013: Added StyleMVVM.

04.07.2013: Ian Johnson contributed some more advanced tests. Interesting to see how slow some containers are, when the object graph gets a little bigger.

26.07.2013: Added IfFastInjector.

03.08.2013: Added Stiletto.

03.09.2013: Updated several containers. Ignored Stiletto since it uses Fody, which makes some problems.

17.11.2013: Added Grace. Updated several containers.

15.12.2013: Added Maestro. Updated several containers.

11.02.2014: Added MEF2.

10.04.2014: Updated benchmark. Updated several containers.

Source code

Latest source code is available on Github.

Downloads

IocPerformance.7z 

 

Original post//www.palmmedia.de/blog/2011/8/30/ioc-container-benchmark-performance-comparison