As most of you know, my favorite is SimpleInjector. I use it in all my projects. Since Sitecore 8.2 was released yesterday (August 30th 2016), I decided to do a performance benchmark against Microsoft Extensions DependencyInjection which is used as part of Sitecore to provide DependencyInjection.
I ran these tests on a virtual with Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz with 8GB memory.
My source is available on GitHub: IoC Performance
In order to do this I have taken two approaches. First, I used the repo from Daniel Palme and his blog post: IoC Container Benchmark – Performance comparison and I updated the NuGet packages. Here is a blurb from Daniels post about the setup:
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.
- 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
- Prepare And Register: Initializes container and registers some basic elements (executed 3.000 times)
- Prepare And Register And Simple Resolve: Initializes container and registers some basic elements. The resolves two objects (executed 3.000 times)
First value: Time of single-threaded execution in [ms]
Second value: Time of multi-threaded execution in [ms]
That produced the following results:
|Version||Singleton||Transient||Combined||Complex||Property||Generics||IEnumerable||Conditional||Child Container||Interception With Proxy||Prepare And Register||Prepare And Register And Simple Resolve|
Second, I took the repos from:
To get the following results:
|Version||Singleton Reg. (ms)||Singleton Resolve (1,000,000) (ms)||Transient Reg. (ms)||Transient Resolve (1,000,000) (ms)|
If you have any questions or concerns, please get in touch with me. (@akshaysura13 on twitter or on Slack).
*Due to the updated AutoFac version I was getting some issues with Daniels code. I will resolve it at a later date and retest it.