Brock Allen <[EMAIL PROTECTED]> wrote: > Was the time the JITer takes to instantiate the generic type taken into > consideration?
The times we're talking about are large in comparison to instantiation & JIT time, with the number of repetitions (1 million). FWIW, here's the times with the first call not timed: Public & Private are classes: Activator.Create(typeof(Public)) : 0.148 sec with 1000000 reps Activator.Create<Public>() : 1.039 sec with 1000000 reps Activator.Create(typeof(Private)) : 1.994 sec with 1000000 reps Activator.Create<Private>() : 1.037 sec with 1000000 reps Public & Private are structs: Activator.Create(typeof(Public)) : 0.109 sec with 1000000 reps Activator.Create<Public>() : 0.170 sec with 1000000 reps Activator.Create(typeof(Private)) : 2.171 sec with 1000000 reps Activator.Create<Private>() : 0.170 sec with 1000000 reps Test program: ---8<--- using System; using System.Diagnostics; //* public class Public { public string field1; } class Private { public string field1; } /*/ public struct Public { public string field1; } struct Private { public string field1; } //*/ public class App { delegate void Proc(); const int Repetitions = 1000000; static void Time(string label, Proc proc) { proc(); // warm up / instantiate etc Stopwatch w = Stopwatch.StartNew(); for (int i = 0; i < Repetitions; ++i) proc(); Console.WriteLine("{0,-35}: {1,6:f3} sec with {2} reps", label, w.ElapsedTicks / (double) Stopwatch.Frequency, Repetitions); } static void Main() { Time("Activator.Create(typeof(Public))", delegate { Public item = (Public) Activator.CreateInstance(typeof(Public)); }); Time("Activator.Create<Public>()", delegate { Public item = Activator.CreateInstance<Public>(); }); Time("Activator.Create(typeof(Private))", delegate { Private item = (Private) Activator.CreateInstance(typeof(Private)); }); Time("Activator.Create<Private>()", delegate { Private item = Activator.CreateInstance<Private>(); }); } } --->8--- -- Barry -- http://barrkel.blogspot.com/ =================================== This list is hosted by DevelopMentor® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com