Category Archives: IOC

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 compiledexpressions 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. Each test is executed single threaded and multi threaded.

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 108
78
126
116
147
168
222
206
348
176
107
106
275
177
214
180
1899
524
88
106
Autofac 3.5.2 893
723
2568
2571
6407
4071
18191
11244
32706
20892
5158
3346
17288
12199
108964
86101
51505
37712
Caliburn.Micro 1.5.2 538
353
670
405
1867
1085
7969
4632
10427
6064
7758
4514
Catel 3.9.0 351
431
4361
4901
13210
14088
32621
36346
12293
13237
4411
4783
DryIoc 1.3.1 37
52
48
60
64
73
98
97
96
94
61
67
310
227
76
71
Dynamo 3.0.2.0 105
80
134
103
234
162
823
493
855
519
fFastInjector 0.8.1 105
81
143
120
194
143
295
203
Funq 1.0.0.0 149
111
181
132
451
338
1327
852
1299
789
Grace 2.3.10 174
134
311
225
787
527
2002
2244
5426
1946
981
588
4315
2458
1145
667
20489
12160
11619
5261
Griffin 1.1.2 374
231
377
243
971
573
2813
1548
HaveBox 2.0.0 91
76
110
95
122
87
222
194
1119
697
2252
1373
868
538
Hiro 1.0.4.41795 207
140
209
146
219
154
290
199
3104
1931
IfInjector 0.8.1 108
86
144
115
180
142
233
166
385
269
170
131
LightCore 1.5.1 203
171
3364
1998
34315
34496
193101*
205435*
2487
1843
23120
15653
52456
31250
LightInject 3.0.1.7 54
59
80
77
85
83
123
109
119
104
79
82
368
262
100
81
1647
1079
LinFu 2.3.0.41559 4163
2443
24399
16041
64412
41898
170694
104578
Maestro 1.4.0 306
243
461
325
1199
766
3443
2124
6693
2348
718
500
3933
2431
1007
644
9134
5777
Mef 4.0.0.0 34967
19746
53521
31946
87598
65396
175864
169289
180329*
178984
198621*
151746
137126
140873
Mef2 1.0.27.0 295
201
290
204
379
439
633
403
1383
887
313
228
2587
2518
MicroSliver 2.1.6.0 566
303
818
543
2901
1802
8322
8170
Mugen 3.5.1 459
359
810
582
2380
1666
9042
6674
11883
7521
71914
76734
6944
7444
2060
1369
706941*
OoM
5051527*
Error
Munq 3.1.6 111
79
283
192
751
454
2389
1482
1899
1169
Ninject 3.2.2.0 7259
4486
24276
15296
69214
39610
191033*
117563
165177
106569
67347
42019
151450
96672
53576
31926
45724250*
37677615*
36162
22413
Petite 0.3.2 6626
4071
5546
3373
6971
4657
8246
6118
6297
3789
SimpleInjector 2.5.2 64
64
92
79
116
95
149
121
248
177
99
85
905
559
221
157
10422
6055
Spring.NET 1.3.2 1046
808
16566
10128
45510
29798
117230
75645
103584
66296
77502
43561
StructureMap 3.1.0.133 2835
2938
2748
6505
11154
10107
29225
27277
24841
34278
8163
8027
25240
21399
4670179*
2961095*
21209
17507
StyleMVVM 3.1.5 656
454
543
383
833
527
2170
2363
2391
1093
1407
881
3703
4850
1598
965
TinyIoC 1.2 421
323
2705
1698
13719
6623
44567
28659
5275
5538
17576
11517
Unity 3.5.1404.0 2873
3812
7182
3038
15294
8012
39116
21296
40234
21537
65395
41530
53041
31885
128682
82599
Windsor 3.3.0 519
383
2626
3658
8893
4861
26098
16700
52083
32659
27157
17004
26641
13537
340330*
Error
21772
13042

Basic features

IocPerformance - Basic features

Advanced features

IocPerformance - Advanced features

Feature comparison

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

http://www.palmmedia.de/blog/2011/8/30/ioc-container-benchmark-performance-comparison