2 using System.Reflection;
9 const int count = 1000000;
11 static void use_new () {
12 for (int i = 0; i < count; ++i)
17 return MemberwiseClone ();
20 static void use_clone () {
22 for (int i = 0; i < count; ++i)
26 static void use_activator () {
27 for (int i = 0; i < count; ++i)
28 Activator.CreateInstance (typeof (T));
31 static void use_ctor () {
32 ConstructorInfo ctor = typeof (T).GetConstructor (Type.EmptyTypes);
33 for (int i = 0; i < count; ++i)
38 long start, end, new_val, perc;
39 start = Environment.TickCount;
41 start = Environment.TickCount;
43 end = Environment.TickCount;
44 Console.WriteLine ("new took {0}", end-start);
47 start = Environment.TickCount;
49 end = Environment.TickCount;
50 perc = ((end-start-new_val) * 100) / new_val;
51 Console.WriteLine ("clone took {0} {1} %", end-start, perc);
53 start = Environment.TickCount;
55 end = Environment.TickCount;
56 perc = ((end-start-new_val) * 100) / new_val;
57 Console.WriteLine ("activator took {0} {1} %", end-start, perc);
59 start = Environment.TickCount;
61 end = Environment.TickCount;
62 perc = ((end-start-new_val) * 100) / new_val;
63 Console.WriteLine ("ctor took {0} {1} %", end-start, perc);