private static void RunBenchmark <TClass, TStruct>() { // ----------------------------------------------------------------------------------------------------------------- Console.WriteLine("### No Constructor Parameters (Generic)"); Console.WriteLine(); WriteHeader(); Measure( ("T Activator.CreateInstance<T>()", () => Activator.CreateInstance <TClass>(), () => Activator.CreateInstance <TStruct>()), ("T FastActivator<T>.CreateInstance()", () => FastActivator <TClass> .CreateInstance(), () => FastActivator <TStruct> .CreateInstance())); Console.WriteLine(); Console.WriteLine(); // ----------------------------------------------------------------------------------------------------------------- Console.WriteLine("### No Constructor Parameters (Non-Generic)"); Console.WriteLine(); WriteHeader(); Measure( ("object Activator.CreateInstance(Type)", () => (TClass)Activator.CreateInstance(typeof(TClass)), () => (TStruct)Activator.CreateInstance(typeof(TStruct))), ("object FastActivator.CreateInstance(Type)", () => (TClass)FastActivator.CreateInstance(typeof(TClass)), () => (TStruct)FastActivator.CreateInstance(typeof(TStruct)))); Console.WriteLine(); Console.WriteLine(); // ----------------------------------------------------------------------------------------------------------------- var constructorArgumentTypesList = new List <Type>(); Type[] constructorArgumentTypes; Console.WriteLine("### 1 Constructor Parameter"); Console.WriteLine(); WriteHeader(); constructorArgumentTypesList.Add(typeof(int)); constructorArgumentTypes = constructorArgumentTypesList.ToArray(); var constructorArgumentsTyped = new int[constructorArgumentTypesList.Count]; // always 0, but does not matter... var constructorArgumentsUntyped = new object[constructorArgumentTypesList.Count]; Array.Copy(constructorArgumentsTyped, constructorArgumentsUntyped, constructorArgumentTypesList.Count); Measure( ("object Activator.CreateInstance(Type, object[])", () => (TClass)Activator.CreateInstance(typeof(TClass), constructorArgumentsUntyped), () => (TStruct)Activator.CreateInstance(typeof(TStruct), constructorArgumentsUntyped)), ("object FastActivator.CreateInstanceDynamically(Type, Type[], object[])", () => (TClass)FastActivator.CreateInstanceDynamically(typeof(TClass), constructorArgumentTypes, constructorArgumentsUntyped), () => (TStruct)FastActivator.CreateInstanceDynamically(typeof(TStruct), constructorArgumentTypes, constructorArgumentsUntyped)), ("object FastActivator.CreateInstance<...>(...)", () => (TClass)FastActivator.CreateInstance(typeof(TClass), 1), () => (TStruct)FastActivator.CreateInstance(typeof(TStruct), 1)), ("T FastActivator<T>.CreateInstance<...>(...)", () => FastActivator <TClass> .CreateInstance(1), () => FastActivator <TStruct> .CreateInstance(1))); Console.WriteLine(); Console.WriteLine(); // ----------------------------------------------------------------------------------------------------------------- Console.WriteLine("### 2 Constructor Parameters"); Console.WriteLine(); WriteHeader(); constructorArgumentTypesList.Add(typeof(int)); constructorArgumentTypes = constructorArgumentTypesList.ToArray(); constructorArgumentsTyped = new int[constructorArgumentTypesList.Count]; // always 0, but does not matter... constructorArgumentsUntyped = new object[constructorArgumentTypesList.Count]; Array.Copy(constructorArgumentsTyped, constructorArgumentsUntyped, constructorArgumentTypesList.Count); Measure( ("object Activator.CreateInstance(Type, object[])", () => (TClass)Activator.CreateInstance(typeof(TClass), constructorArgumentsUntyped), () => (TStruct)Activator.CreateInstance(typeof(TStruct), constructorArgumentsUntyped)), ("object FastActivator.CreateInstanceDynamically(Type, Type[], object[])", () => (TClass)FastActivator.CreateInstanceDynamically(typeof(TClass), constructorArgumentTypes, constructorArgumentsUntyped), () => (TStruct)FastActivator.CreateInstanceDynamically(typeof(TStruct), constructorArgumentTypes, constructorArgumentsUntyped)), ("object FastActivator.CreateInstance<...>(...)", () => (TClass)FastActivator.CreateInstance(typeof(TClass), 1, 2), () => (TStruct)FastActivator.CreateInstance(typeof(TStruct), 1, 2)), ("T FastActivator<T>.CreateInstance<...>(...)", () => FastActivator <TClass> .CreateInstance(1, 2), () => FastActivator <TStruct> .CreateInstance(1, 2))); Console.WriteLine(); Console.WriteLine(); // ----------------------------------------------------------------------------------------------------------------- Console.WriteLine("### 3 Constructor Parameters"); Console.WriteLine(); WriteHeader(); constructorArgumentTypesList.Add(typeof(int)); constructorArgumentTypes = constructorArgumentTypesList.ToArray(); constructorArgumentsTyped = new int[constructorArgumentTypesList.Count]; // always 0, but does not matter... constructorArgumentsUntyped = new object[constructorArgumentTypesList.Count]; Array.Copy(constructorArgumentsTyped, constructorArgumentsUntyped, constructorArgumentTypesList.Count); Measure( ("object Activator.CreateInstance(Type, object[])", () => (TClass)Activator.CreateInstance(typeof(TClass), constructorArgumentsUntyped), () => (TStruct)Activator.CreateInstance(typeof(TStruct), constructorArgumentsUntyped)), ("object FastActivator.CreateInstanceDynamically(Type, Type[], object[])", () => (TClass)FastActivator.CreateInstanceDynamically(typeof(TClass), constructorArgumentTypes, constructorArgumentsUntyped), () => (TStruct)FastActivator.CreateInstanceDynamically(typeof(TStruct), constructorArgumentTypes, constructorArgumentsUntyped)), ("object FastActivator.CreateInstance<...>(...)", () => (TClass)FastActivator.CreateInstance(typeof(TClass), 1, 2, 3), () => (TStruct)FastActivator.CreateInstance(typeof(TStruct), 1, 2, 3)), ("T FastActivator<T>.CreateInstance<...>(...)", () => FastActivator <TClass> .CreateInstance(1, 2, 3), () => FastActivator <TStruct> .CreateInstance(1, 2, 3))); Console.WriteLine(); Console.WriteLine(); // ----------------------------------------------------------------------------------------------------------------- Console.WriteLine("### 4 Constructor Parameters"); Console.WriteLine(); WriteHeader(); constructorArgumentTypesList.Add(typeof(int)); constructorArgumentTypes = constructorArgumentTypesList.ToArray(); constructorArgumentsTyped = new int[constructorArgumentTypesList.Count]; // always 0, but does not matter... constructorArgumentsUntyped = new object[constructorArgumentTypesList.Count]; Array.Copy(constructorArgumentsTyped, constructorArgumentsUntyped, constructorArgumentTypesList.Count); Measure( ("object Activator.CreateInstance(Type, object[])", () => (TClass)Activator.CreateInstance(typeof(TClass), constructorArgumentsUntyped), () => (TStruct)Activator.CreateInstance(typeof(TStruct), constructorArgumentsUntyped)), ("object FastActivator.CreateInstanceDynamically(Type, Type[], object[])", () => (TClass)FastActivator.CreateInstanceDynamically(typeof(TClass), constructorArgumentTypes, constructorArgumentsUntyped), () => (TStruct)FastActivator.CreateInstanceDynamically(typeof(TStruct), constructorArgumentTypes, constructorArgumentsUntyped)), ("object FastActivator.CreateInstance<...>(...)", () => (TClass)FastActivator.CreateInstance(typeof(TClass), 1, 2, 3, 4), () => (TStruct)FastActivator.CreateInstance(typeof(TStruct), 1, 2, 3, 4)), ("T FastActivator<T>.CreateInstance<...>(...)", () => FastActivator <TClass> .CreateInstance(1, 2, 3, 4), () => FastActivator <TStruct> .CreateInstance(1, 2, 3, 4))); Console.WriteLine(); Console.WriteLine(); // ----------------------------------------------------------------------------------------------------------------- Console.WriteLine("### 5 Constructor Parameters"); Console.WriteLine(); WriteHeader(); constructorArgumentTypesList.Add(typeof(int)); constructorArgumentTypes = constructorArgumentTypesList.ToArray(); constructorArgumentsTyped = new int[constructorArgumentTypesList.Count]; // always 0, but does not matter... constructorArgumentsUntyped = new object[constructorArgumentTypesList.Count]; Array.Copy(constructorArgumentsTyped, constructorArgumentsUntyped, constructorArgumentTypesList.Count); Measure( ("object Activator.CreateInstance(Type, object[])", () => (TClass)Activator.CreateInstance(typeof(TClass), constructorArgumentsUntyped), () => (TStruct)Activator.CreateInstance(typeof(TStruct), constructorArgumentsUntyped)), ("object FastActivator.CreateInstanceDynamically(Type, Type[], object[])", () => (TClass)FastActivator.CreateInstanceDynamically(typeof(TClass), constructorArgumentTypes, constructorArgumentsUntyped), () => (TStruct)FastActivator.CreateInstanceDynamically(typeof(TStruct), constructorArgumentTypes, constructorArgumentsUntyped)), ("object FastActivator.CreateInstance<...>(...)", () => (TClass)FastActivator.CreateInstance(typeof(TClass), 1, 2, 3, 4, 5), () => (TStruct)FastActivator.CreateInstance(typeof(TStruct), 1, 2, 3, 4, 5)), ("T FastActivator<T>.CreateInstance<...>(...)", () => FastActivator <TClass> .CreateInstance(1, 2, 3, 4, 5), () => FastActivator <TStruct> .CreateInstance(1, 2, 3, 4, 5))); Console.WriteLine(); Console.WriteLine(); // ----------------------------------------------------------------------------------------------------------------- Console.WriteLine("### 6 Constructor Parameters"); Console.WriteLine(); WriteHeader(); constructorArgumentTypesList.Add(typeof(int)); constructorArgumentTypes = constructorArgumentTypesList.ToArray(); constructorArgumentsTyped = new int[constructorArgumentTypesList.Count]; // always 0, but does not matter... constructorArgumentsUntyped = new object[constructorArgumentTypesList.Count]; Array.Copy(constructorArgumentsTyped, constructorArgumentsUntyped, constructorArgumentTypesList.Count); Measure( ("object Activator.CreateInstance(Type, object[])", () => (TClass)Activator.CreateInstance(typeof(TClass), constructorArgumentsUntyped), () => (TStruct)Activator.CreateInstance(typeof(TStruct), constructorArgumentsUntyped)), ("object FastActivator.CreateInstanceDynamically(Type, Type[], object[])", () => (TClass)FastActivator.CreateInstanceDynamically(typeof(TClass), constructorArgumentTypes, constructorArgumentsUntyped), () => (TStruct)FastActivator.CreateInstanceDynamically(typeof(TStruct), constructorArgumentTypes, constructorArgumentsUntyped)), ("object FastActivator.CreateInstance<...>(...)", () => (TClass)FastActivator.CreateInstance(typeof(TClass), 1, 2, 3, 4, 5, 6), () => (TStruct)FastActivator.CreateInstance(typeof(TStruct), 1, 2, 3, 4, 5, 6)), ("T FastActivator<T>.CreateInstance<...>(...)", () => FastActivator <TClass> .CreateInstance(1, 2, 3, 4, 5, 6), () => FastActivator <TStruct> .CreateInstance(1, 2, 3, 4, 5, 6))); Console.WriteLine(); Console.WriteLine(); // ----------------------------------------------------------------------------------------------------------------- Console.WriteLine("### 7 Constructor Parameters"); Console.WriteLine(); WriteHeader(); constructorArgumentTypesList.Add(typeof(int)); constructorArgumentTypes = constructorArgumentTypesList.ToArray(); constructorArgumentsTyped = new int[constructorArgumentTypesList.Count]; // always 0, but does not matter... constructorArgumentsUntyped = new object[constructorArgumentTypesList.Count]; Array.Copy(constructorArgumentsTyped, constructorArgumentsUntyped, constructorArgumentTypesList.Count); Measure( ("object Activator.CreateInstance(Type, object[])", () => (TClass)Activator.CreateInstance(typeof(TClass), constructorArgumentsUntyped), () => (TStruct)Activator.CreateInstance(typeof(TStruct), constructorArgumentsUntyped)), ("object FastActivator.CreateInstanceDynamically(Type, Type[], object[])", () => (TClass)FastActivator.CreateInstanceDynamically(typeof(TClass), constructorArgumentTypes, constructorArgumentsUntyped), () => (TStruct)FastActivator.CreateInstanceDynamically(typeof(TStruct), constructorArgumentTypes, constructorArgumentsUntyped)), ("object FastActivator.CreateInstance<...>(...)", () => (TClass)FastActivator.CreateInstance(typeof(TClass), 1, 2, 3, 4, 5, 6, 7), () => (TStruct)FastActivator.CreateInstance(typeof(TStruct), 1, 2, 3, 4, 5, 6, 7)), ("T FastActivator<T>.CreateInstance<...>(...)", () => FastActivator <TClass> .CreateInstance(1, 2, 3, 4, 5, 6, 7), () => FastActivator <TStruct> .CreateInstance(1, 2, 3, 4, 5, 6, 7))); Console.WriteLine(); Console.WriteLine(); // ----------------------------------------------------------------------------------------------------------------- Console.WriteLine("### 8 Constructor Parameters"); Console.WriteLine(); WriteHeader(); constructorArgumentTypesList.Add(typeof(int)); constructorArgumentTypes = constructorArgumentTypesList.ToArray(); constructorArgumentsTyped = new int[constructorArgumentTypesList.Count]; // always 0, but does not matter... constructorArgumentsUntyped = new object[constructorArgumentTypesList.Count]; Array.Copy(constructorArgumentsTyped, constructorArgumentsUntyped, constructorArgumentTypesList.Count); Measure( ("object Activator.CreateInstance(Type, object[])", () => (TClass)Activator.CreateInstance(typeof(TClass), constructorArgumentsUntyped), () => (TStruct)Activator.CreateInstance(typeof(TStruct), constructorArgumentsUntyped)), ("object FastActivator.CreateInstanceDynamically(Type, Type[], object[])", () => (TClass)FastActivator.CreateInstanceDynamically(typeof(TClass), constructorArgumentTypes, constructorArgumentsUntyped), () => (TStruct)FastActivator.CreateInstanceDynamically(typeof(TStruct), constructorArgumentTypes, constructorArgumentsUntyped)), ("object FastActivator.CreateInstance<...>(...)", () => (TClass)FastActivator.CreateInstance(typeof(TClass), 1, 2, 3, 4, 5, 6, 7, 8), () => (TStruct)FastActivator.CreateInstance(typeof(TStruct), 1, 2, 3, 4, 5, 6, 7, 8)), ("T FastActivator<T>.CreateInstance<...>(...)", () => FastActivator <TClass> .CreateInstance(1, 2, 3, 4, 5, 6, 7, 8), () => FastActivator <TStruct> .CreateInstance(1, 2, 3, 4, 5, 6, 7, 8))); Console.WriteLine(); Console.WriteLine(); // ----------------------------------------------------------------------------------------------------------------- Console.WriteLine("### 9 Constructor Parameters"); Console.WriteLine(); WriteHeader(); constructorArgumentTypesList.Add(typeof(int)); constructorArgumentTypes = constructorArgumentTypesList.ToArray(); constructorArgumentsTyped = new int[constructorArgumentTypesList.Count]; // always 0, but does not matter... constructorArgumentsUntyped = new object[constructorArgumentTypesList.Count]; Array.Copy(constructorArgumentsTyped, constructorArgumentsUntyped, constructorArgumentTypesList.Count); Measure( ("object Activator.CreateInstance(Type, object[])", () => (TClass)Activator.CreateInstance(typeof(TClass), constructorArgumentsUntyped), () => (TStruct)Activator.CreateInstance(typeof(TStruct), constructorArgumentsUntyped)), ("object FastActivator.CreateInstanceDynamically(Type, Type[], object[])", () => (TClass)FastActivator.CreateInstanceDynamically(typeof(TClass), constructorArgumentTypes, constructorArgumentsUntyped), () => (TStruct)FastActivator.CreateInstanceDynamically(typeof(TStruct), constructorArgumentTypes, constructorArgumentsUntyped)), ("object FastActivator.CreateInstance<...>(...)", () => (TClass)FastActivator.CreateInstance(typeof(TClass), 1, 2, 3, 4, 5, 6, 7, 8, 9), () => (TStruct)FastActivator.CreateInstance(typeof(TStruct), 1, 2, 3, 4, 5, 6, 7, 8, 9)), ("T FastActivator<T>.CreateInstance<...>(...)", () => FastActivator <TClass> .CreateInstance(1, 2, 3, 4, 5, 6, 7, 8, 9), () => FastActivator <TStruct> .CreateInstance(1, 2, 3, 4, 5, 6, 7, 8, 9))); Console.WriteLine(); Console.WriteLine(); // ----------------------------------------------------------------------------------------------------------------- Console.WriteLine("### 10 Constructor Parameters"); Console.WriteLine(); WriteHeader(); constructorArgumentTypesList.Add(typeof(int)); constructorArgumentTypes = constructorArgumentTypesList.ToArray(); constructorArgumentsTyped = new int[constructorArgumentTypesList.Count]; // always 0, but does not matter... constructorArgumentsUntyped = new object[constructorArgumentTypesList.Count]; Array.Copy(constructorArgumentsTyped, constructorArgumentsUntyped, constructorArgumentTypesList.Count); Measure( ("object Activator.CreateInstance(Type, object[])", () => (TClass)Activator.CreateInstance(typeof(TClass), constructorArgumentsUntyped), () => (TStruct)Activator.CreateInstance(typeof(TStruct), constructorArgumentsUntyped)), ("object FastActivator.CreateInstanceDynamically(Type, Type[], object[])", () => (TClass)FastActivator.CreateInstanceDynamically(typeof(TClass), constructorArgumentTypes, constructorArgumentsUntyped), () => (TStruct)FastActivator.CreateInstanceDynamically(typeof(TStruct), constructorArgumentTypes, constructorArgumentsUntyped)), ("object FastActivator.CreateInstance<...>(...)", () => (TClass)FastActivator.CreateInstance(typeof(TClass), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10), () => (TStruct)FastActivator.CreateInstance(typeof(TStruct), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)), ("T FastActivator<T>.CreateInstance<...>(...)", () => FastActivator <TClass> .CreateInstance(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), () => FastActivator <TStruct> .CreateInstance(1, 2, 3, 4, 5, 6, 7, 8, 9, 10))); Console.WriteLine(); Console.WriteLine(); // ----------------------------------------------------------------------------------------------------------------- Console.WriteLine("### 11 Constructor Parameters"); Console.WriteLine(); WriteHeader(); constructorArgumentTypesList.Add(typeof(int)); constructorArgumentTypes = constructorArgumentTypesList.ToArray(); constructorArgumentsTyped = new int[constructorArgumentTypesList.Count]; // always 0, but does not matter... constructorArgumentsUntyped = new object[constructorArgumentTypesList.Count]; Array.Copy(constructorArgumentsTyped, constructorArgumentsUntyped, constructorArgumentTypesList.Count); Measure( ("object Activator.CreateInstance(Type, object[])", () => (TClass)Activator.CreateInstance(typeof(TClass), constructorArgumentsUntyped), () => (TStruct)Activator.CreateInstance(typeof(TStruct), constructorArgumentsUntyped)), ("object FastActivator.CreateInstanceDynamically(Type, Type[], object[])", () => (TClass)FastActivator.CreateInstanceDynamically(typeof(TClass), constructorArgumentTypes, constructorArgumentsUntyped), () => (TStruct)FastActivator.CreateInstanceDynamically(typeof(TStruct), constructorArgumentTypes, constructorArgumentsUntyped)), ("object FastActivator.CreateInstance<...>(...)", () => (TClass)FastActivator.CreateInstance(typeof(TClass), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11), () => (TStruct)FastActivator.CreateInstance(typeof(TStruct), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)), ("T FastActivator.CreateInstance<...>(...)", () => FastActivator <TClass> .CreateInstance(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11), () => FastActivator <TStruct> .CreateInstance(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11))); Console.WriteLine(); Console.WriteLine(); // ----------------------------------------------------------------------------------------------------------------- Console.WriteLine("### 12 Constructor Parameters"); Console.WriteLine(); WriteHeader(); constructorArgumentTypesList.Add(typeof(int)); constructorArgumentTypes = constructorArgumentTypesList.ToArray(); constructorArgumentsTyped = new int[constructorArgumentTypesList.Count]; // always 0, but does not matter... constructorArgumentsUntyped = new object[constructorArgumentTypesList.Count]; Array.Copy(constructorArgumentsTyped, constructorArgumentsUntyped, constructorArgumentTypesList.Count); Measure( ("object Activator.CreateInstance(Type, object[])", () => (TClass)Activator.CreateInstance(typeof(TClass), constructorArgumentsUntyped), () => (TStruct)Activator.CreateInstance(typeof(TStruct), constructorArgumentsUntyped)), ("object FastActivator.CreateInstanceDynamically(Type, Type[], object[])", () => (TClass)FastActivator.CreateInstanceDynamically(typeof(TClass), constructorArgumentTypes, constructorArgumentsUntyped), () => (TStruct)FastActivator.CreateInstanceDynamically(typeof(TStruct), constructorArgumentTypes, constructorArgumentsUntyped)), ("object FastActivator.CreateInstance<...>(...)", () => (TClass)FastActivator.CreateInstance(typeof(TClass), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), () => (TStruct)FastActivator.CreateInstance(typeof(TStruct), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)), ("T FastActivator<T>.CreateInstance<...>(...)", () => FastActivator <TClass> .CreateInstance(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), () => FastActivator <TStruct> .CreateInstance(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12))); Console.WriteLine(); Console.WriteLine(); // ----------------------------------------------------------------------------------------------------------------- Console.WriteLine("### 13 Constructor Parameters"); Console.WriteLine(); WriteHeader(); constructorArgumentTypesList.Add(typeof(int)); constructorArgumentTypes = constructorArgumentTypesList.ToArray(); constructorArgumentsTyped = new int[constructorArgumentTypesList.Count]; // always 0, but does not matter... constructorArgumentsUntyped = new object[constructorArgumentTypesList.Count]; Array.Copy(constructorArgumentsTyped, constructorArgumentsUntyped, constructorArgumentTypesList.Count); Measure( ("object Activator.CreateInstance(Type, object[])", () => (TClass)Activator.CreateInstance(typeof(TClass), constructorArgumentsUntyped), () => (TStruct)Activator.CreateInstance(typeof(TStruct), constructorArgumentsUntyped)), ("object FastActivator.CreateInstanceDynamically(Type, Type[], object[])", () => (TClass)FastActivator.CreateInstanceDynamically(typeof(TClass), constructorArgumentTypes, constructorArgumentsUntyped), () => (TStruct)FastActivator.CreateInstanceDynamically(typeof(TStruct), constructorArgumentTypes, constructorArgumentsUntyped)), ("object FastActivator.CreateInstance<...>(...)", () => (TClass)FastActivator.CreateInstance(typeof(TClass), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13), () => (TStruct)FastActivator.CreateInstance(typeof(TStruct), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)), ("T FastActivator<T>.CreateInstance<...>(...)", () => FastActivator <TClass> .CreateInstance(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13), () => FastActivator <TStruct> .CreateInstance(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13))); Console.WriteLine(); Console.WriteLine(); // ----------------------------------------------------------------------------------------------------------------- Console.WriteLine("### 14 Constructor Parameters"); Console.WriteLine(); WriteHeader(); constructorArgumentTypesList.Add(typeof(int)); constructorArgumentTypes = constructorArgumentTypesList.ToArray(); constructorArgumentsTyped = new int[constructorArgumentTypesList.Count]; // always 0, but does not matter... constructorArgumentsUntyped = new object[constructorArgumentTypesList.Count]; Array.Copy(constructorArgumentsTyped, constructorArgumentsUntyped, constructorArgumentTypesList.Count); Measure( ("object Activator.CreateInstance(Type, object[])", () => (TClass)Activator.CreateInstance(typeof(TClass), constructorArgumentsUntyped), () => (TStruct)Activator.CreateInstance(typeof(TStruct), constructorArgumentsUntyped)), ("object FastActivator.CreateInstanceDynamically(Type, Type[], object[])", () => (TClass)FastActivator.CreateInstanceDynamically(typeof(TClass), constructorArgumentTypes, constructorArgumentsUntyped), () => (TStruct)FastActivator.CreateInstanceDynamically(typeof(TStruct), constructorArgumentTypes, constructorArgumentsUntyped)), ("object FastActivator.CreateInstance<...>(...)", () => (TClass)FastActivator.CreateInstance(typeof(TClass), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14), () => (TStruct)FastActivator.CreateInstance(typeof(TStruct), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14)), ("T FastActivator<T>.CreateInstance<...>(...)", () => FastActivator <TClass> .CreateInstance(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14), () => FastActivator <TStruct> .CreateInstance(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14))); Console.WriteLine(); Console.WriteLine(); // ----------------------------------------------------------------------------------------------------------------- Console.WriteLine("### 15 Constructor Parameters"); Console.WriteLine(); WriteHeader(); constructorArgumentTypesList.Add(typeof(int)); constructorArgumentTypes = constructorArgumentTypesList.ToArray(); constructorArgumentsTyped = new int[constructorArgumentTypesList.Count]; // always 0, but does not matter... constructorArgumentsUntyped = new object[constructorArgumentTypesList.Count]; Array.Copy(constructorArgumentsTyped, constructorArgumentsUntyped, constructorArgumentTypesList.Count); Measure( ("object Activator.CreateInstance(Type, object[])", () => (TClass)Activator.CreateInstance(typeof(TClass), constructorArgumentsUntyped), () => (TStruct)Activator.CreateInstance(typeof(TStruct), constructorArgumentsUntyped)), ("object FastActivator.CreateInstanceDynamically(Type, Type[], object[])", () => (TClass)FastActivator.CreateInstanceDynamically(typeof(TClass), constructorArgumentTypes, constructorArgumentsUntyped), () => (TStruct)FastActivator.CreateInstanceDynamically(typeof(TStruct), constructorArgumentTypes, constructorArgumentsUntyped)), ("object FastActivator.CreateInstance<...>(...)", () => (TClass)FastActivator.CreateInstance(typeof(TClass), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15), () => (TStruct)FastActivator.CreateInstance(typeof(TStruct), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)), ("T FastActivator<T>.CreateInstance<...>(...)", () => FastActivator <TClass> .CreateInstance(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15), () => FastActivator <TStruct> .CreateInstance(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15))); Console.WriteLine(); Console.WriteLine(); // ----------------------------------------------------------------------------------------------------------------- Console.WriteLine("### 16 Constructor Parameters"); Console.WriteLine(); WriteHeader(); constructorArgumentTypesList.Add(typeof(int)); constructorArgumentTypes = constructorArgumentTypesList.ToArray(); constructorArgumentsTyped = new int[constructorArgumentTypesList.Count]; // always 0, but does not matter... constructorArgumentsUntyped = new object[constructorArgumentTypesList.Count]; Array.Copy(constructorArgumentsTyped, constructorArgumentsUntyped, constructorArgumentTypesList.Count); Measure( ("object Activator.CreateInstance(Type, object[])", () => (TClass)Activator.CreateInstance(typeof(TClass), constructorArgumentsUntyped), () => (TStruct)Activator.CreateInstance(typeof(TStruct), constructorArgumentsUntyped)), ("object FastActivator.CreateInstanceDynamically(Type, Type[], object[])", () => (TClass)FastActivator.CreateInstanceDynamically(typeof(TClass), constructorArgumentTypes, constructorArgumentsUntyped), () => (TStruct)FastActivator.CreateInstanceDynamically(typeof(TStruct), constructorArgumentTypes, constructorArgumentsUntyped)), ("object FastActivator.CreateInstance<...>(...)", () => (TClass)FastActivator.CreateInstance(typeof(TClass), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), () => (TStruct)FastActivator.CreateInstance(typeof(TStruct), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)), ("T FastActivator<T>.CreateInstance<...>(...)", () => FastActivator <TClass> .CreateInstance(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), () => FastActivator <TStruct> .CreateInstance(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16))); Console.WriteLine(); Console.WriteLine(); // ----------------------------------------------------------------------------------------------------------------- }