Object construction.
authorPaolo Molaro <lupus@oddwiz.org>
Wed, 14 May 2003 16:34:10 +0000 (16:34 -0000)
committerPaolo Molaro <lupus@oddwiz.org>
Wed, 14 May 2003 16:34:10 +0000 (16:34 -0000)
svn path=/trunk/mono/; revision=14582

mono/benchmark/Makefile.am
mono/benchmark/ctor-bench.cs [new file with mode: 0644]

index 40dfaa5d3c8f56b41ed570d357f0f86a7e2477a3..4db8e150a63a8bfd428831c1b3c7323d36cc1791 100644 (file)
@@ -20,6 +20,7 @@ TESTSRC=                      \
        initlocals.cs           \
        logic.cs                \
        switch.cs               \
+       ctor-bench.cs           \
        bulkcpy.il              \
        math.cs
 
diff --git a/mono/benchmark/ctor-bench.cs b/mono/benchmark/ctor-bench.cs
new file mode 100644 (file)
index 0000000..31099ac
--- /dev/null
@@ -0,0 +1,67 @@
+using System;
+using System.Reflection;
+
+class T {
+
+       public T () {
+       }
+
+       const int count = 1000000;
+
+       static void use_new () {
+               for (int i = 0; i < count; ++i) 
+                       new T ();
+       }
+
+       object Clone () {
+               return MemberwiseClone ();
+       }
+       
+       static void use_clone () {
+               T t = new T ();
+               for (int i = 0; i < count; ++i) 
+                       t.Clone ();
+       }
+       
+       static void use_activator () {
+               for (int i = 0; i < count; ++i) 
+                       Activator.CreateInstance (typeof (T));
+       }
+       
+       static void use_ctor () {
+               ConstructorInfo ctor = typeof (T).GetConstructor (Type.EmptyTypes);
+               for (int i = 0; i < count; ++i) 
+                       ctor.Invoke (null);
+       }
+       
+       static void Main () {
+               long start, end, new_val, perc;
+               start = Environment.TickCount;
+
+               start = Environment.TickCount;
+               use_new ();
+               end = Environment.TickCount;
+               Console.WriteLine ("new took {0}", end-start);
+               new_val = end-start;
+
+               start = Environment.TickCount;
+               use_clone ();
+               end = Environment.TickCount;
+               perc = ((end-start-new_val) * 100) / new_val;
+               Console.WriteLine ("clone took {0} {1} %", end-start, perc);
+
+               start = Environment.TickCount;
+               use_activator ();
+               end = Environment.TickCount;
+               perc = ((end-start-new_val) * 100) / new_val;
+               Console.WriteLine ("activator took {0} {1} %", end-start, perc);
+
+               start = Environment.TickCount;
+               use_ctor ();
+               end = Environment.TickCount;
+               perc = ((end-start-new_val) * 100) / new_val;
+               Console.WriteLine ("ctor took {0} {1} %", end-start, perc);
+
+       }
+}
+