Over a million developers have joined DZone.

Unity, Castle Windsor, StructureMap, Ninject – who has best performance?

DZone's Guide to

Unity, Castle Windsor, StructureMap, Ninject – who has best performance?

· Performance Zone
Free Resource

Discover 50 of the latest mobile performance statistics with the Ultimate Guide to Digital Experience Monitoring, brought to you in partnership with Catchpoint.

I made quick comparison of performance of four DI/IoC containers. I measured Unity, Castle Windsor, StructureMap and Ninject in two scenarios – resolving objects with empty constructor and resolving object with injected parameters in its constructor. Results are here.

As a first thing I made carefully sure that objects are created when resolve methods are called. The results for resolving object with default constructor by interface are here.

4 DI/IoC containers: creating objects with default constructor

In second round I let mappers resolve type that needs constructor parameters and these parameters were injected my DI/IoC containers. Times changed a little bit but TOP4 stayed the same.

4 DI/IoC containers: creating complex objects

Here are comparison chart of results for both measurements.

4 DI/IoC containers: performance comparison chart

StructureMap that is old veteran on field when considering .NET gives best results. Unity and Castle Windsor have also good results although Unity works faster in more complex scenarios. Ninject was slowest, although they use lightweight code generation (LCG). You can also read about my object to object mapper experiment and LCG to get better idea what LCG is all about.

Currently, I think, I will stick with StructureMap as they also have pretty good fluent API that was asy to learn and easy to use. I also hope that other competitors give better results in their next versions.

Update 1: Autofac gave me the following results - 9 and 16 for first and second test. So it seems like they are fastest ones. Thanks for suggestion, Robert!

Update 2: Units on charts are ticks. It is average over one million calls to pre-warmed resolve.

Is your APM strategy broken? This ebook explores the latest in Gartner research to help you learn how to close the end-user experience gap in APM, brought to you in partnership with Catchpoint.


Published at DZone with permission of Gunnar Peipman, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}