IoC Container Benchmark - Performance comparison

Announcements

This arctile is posted by Daniel Palme, who is a .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 setup

The contestants

You probably have heard of most of the frameworks, but one of them is quite new and works differently:  Hiro The author, Philip Laureano, 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 results

Overview

ContainerSingletonTransientCombinedInterception
No1328163 
AutoFac 3.0.27491806457033765
Caliburn.Micro 1.5.1194226651 
Catel 3.52589522846 
Dynamo 3.0.1.07284139 
Funq 1.0.0.08192277 
Griffin 1.1.0194195481 
Hiro 1.0.3101103107 
LightCore 1.5.1156234312045 
LightInject 3.0.0.5171178298 
LinFu 2.3.0.4155928761756447712 
Mef 4.0.0.02507872424937 
MicroSliver 2.1.6.01504852019 
Mugen 3.5.13024831404 
Munq 3.1.6102131412 
Ninject 3.0.1.1067911931454926 
Petite 0.3.28686260 
SimpleInjector 2.2.36887101467
Speedioc 0.1.339610994 
Spring.NET 1.3.26721456039065666
StructureMap 2.6.4.11127121343797329
TinyIOC 1.224615006098 
Unity 3.0.1304.02451380711212103682
Windsor 3.2.04562422697016677

 Singleton

Transient

Combined

Feature comparison

 PerformanceConfigurationFeaturesEnvironment
Container CodeXMLAutoAutowiringCustom lifetimesInterception.NETSLWP7WinRT
AutoFacAverageYesYesYesYesNoYesYesYesYesYes
Caliburn.MicroAverageNoNoNoYesNoNoYesYesYesYes
CatelAverageYesNoNoYesYesNoYesYesYesYes
DynamoFastYesNoYesYesYesNoYesNoNoNo
FunqFastYesNoNoNoNoNoYesYesYesNo
GriffinFastYesNoNoYesNoYesYesNoNoNo
HiroFastYesNoNoYesNoNoYesNoNoNo
LightCoreAverageYesYesYesYesYesNoYesYesNoNo
LightInjectFastYesNoYesNoYesNoYesYesNoNo
LinFuSlowYesNoNoYesNoYesYesNoNoNo
MEFSlowYesNoNoYesNoNoYesYesNoYes
MicroSliverAverageYesNoNoYesNoNoYesYesNoYes
MugenAverageYesNoNoYesYesNoYesYesYesYes
MunqFastYesNoNoYesYesNoYesNoYesNo
NinjectSlowYesNoYesYesYesNoYesYesYesYes
PetiteFastYesNoNoNoNoNoYesNoNoNo
SimpleInjectorFastYesNoYesYesYesYesYesYesNoNo
SpeediocFastYesNoNoNoNoNoYesNoNoNo
Spring.NETVery slowNoYesNoYesNoYesYesNoNoNo
StructureMapAverageYesYesYesYesYesYesYesNoYesNo
TinyIocAverageYesNoYesYesYesNoYesYesYesNo
UnityAverageYesYesNoYesYesYesYesYesNoYes
WindsorAverageYesYesYesYesYesYesYesYesNoNo

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: 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

Source code

Latest source code is available on Github.

Downloads

IocPerformance.7z 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值