Tag: Test

  • C# Dynamic Object Creation Performance

    Recently I had to task to create a dynamic object creation factory in C#. So I thought I test all the options I have to check what performs best.

    I also wanted to check the performance implications these options have with the number of parameters in the constructor.

    The Options

    1. new T() – Using the new/constructor method to
      instantiate objects
    2. Activator.CreateInstance(typeof(T)) – Using the Activator class to instantiate objects
    3. ConstructorInfo.Invoke() – Using the constructor info reflection class to instantiate objects
    4. Func<T>() – Using compiled lambda expressions to instantiate objects

    The Test

    I ran some tests to see calculate how each …