.NET IoC Container Performance


A couple of years ago (~August 2012), we had to choose an IoC container for a new .NET project. Given the many mature options with largely similar feature sets, we based the decision on their performance. The existing benchmarks published on the web left us dissatisfied due to overly simplistic test data. Ideally, the test data should have a large dependency graph to thoroughly exercise the container's ability to resolve.

Using T4 templates, it's simple to create C# classes and interfaces that fit that structure. Using a generic interface to configure the container, it is then easy to provide an implementation for each candidate.

Test Data

The configuration of generated test data is:

  • 8 levels of depth for the dependency tree
  • 100 types per level
  • Between 0 and 8 dependencies for each type (excluding level 0)
  • 1 in 5 types are registered as singleton (20%)

These parameters can be tweaked (TestTypeGeneratorSetup.ttinclude) to simulate alternative scenarios.

It's an exaggerated example but serves the purpose of stress testing. In fact, some of the containers fail to complete the test.

Test data dependencies


Container 2012 Version 2012 Time Elapsed (Sec) 2014 Version Time Elapsed (Sec)
Ninject 31.29 30.84
StructureMap 2.6.2 1.98 1.95
Autofac 5.56 3.5.2 5.19
Castle Windsor 3.1.0 5.47 3.3.0 5.59
Unity 2.1.505.2 7.76 3.5.1404.0 3.71
SimpleInjector 34.43 2.5.2 48.01
Dynamo Fail 3.0.2 Fail
Hiro 1.0.2 Fail 1.0.2 Fail

Dynamo & Hiro failed to complete the test.


From this, it appears that StructureMap is the fastest container to register and resolve all 800 types.

Updating to the latest version (as of Oct 2014) shows that Unity is the biggest winner in terms of speed gain. The rest are largely unchanged.

So if you’re looking for outright performance, give StuctureMap a look.
Since version 3.0.0 it also comes as a Portable Class Library (PCL) so is easy to recommend.

Check out / fork the code on github:


All credits for this blog post and associated source code go to Paul Spiteri.


Olivier Deheurles

Co-founder and Chief Technology Officer,
Adaptive Financial Consulting


Contact us

    By pressing "Send" I agree that I am happy to be contacted by Adaptive Financial Consulting. I can unsubscribe at any time. You can read more about our privacy policy here.