15
votes

I've found some 2008 benchmark results for testing the performance of several of the top .NET DI/IoC containers here. But I haven't been able to find any updated results. Are there any benchmarks out there that compare some of the big IoC containers (StructureMap, Unity, Ninject, Autofac, Castle Windsor, etc.)?

3
I agree with Reed. Besides, benchmarks are easy to get wrong. Look for instance at this thread: stackoverflow.com/questions/5298240/….Steven
The fact that such new benchmarks are missing from the net, I take as a statement that this is of lesser concern.Peter Lillevold

3 Answers

45
votes

I would not recommend using performance benchmarks to pick an IoC container. There are many, many more important factors, such as feature set, development roadmap and maintainability, etc.

Realize that the benchmark you're citing is, in the worst case, only showing a 3-4x difference in speed over 1 million calls. In a "real world" scenario, DI/IoC is used to wire up dependencies, and will have a very minimal impact on overall application performance, as this construction phase is an incredibly small portion of your overall runtime. Choosing a "high performance" vs. a "low performance" IoC container will likely have no discernible impact on your application's perceived performance.

In the unlikely scenario that performance is truly important to your specific usage case, a benchmark is unlikely to be a valid measure of how the IoC container's performance will impact you, as benchmarks tend to be skewed towards a specific problem set. I would highly recommend doing your own profiling and measurement if you truly believe this is a serious issue.

6
votes

In my case, speed of IoC container has been an important factor. I've had an application that performs many injections and found that Ninject was slowing the application down considerably. Taking out the IoC completely solved the performance issues. I will be looking into other solutions.

6
votes

IoC Container Benchmark - Performance comparison has performance and features comparison tables for 20+ products and it is up-to-date (latest update 21.12.2017)

The conclusion from the article:

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.

See also related https://stackguides.com/questions/1140730/net-di-containers-comparison/ question.