From e276e26955ce49bea7dcccb5a364ffd5faffcd5e Mon Sep 17 00:00:00 2001 From: Paolo Molaro Date: Wed, 14 May 2003 16:34:10 +0000 Subject: [PATCH] Object construction. svn path=/trunk/mono/; revision=14582 --- mono/benchmark/Makefile.am | 1 + mono/benchmark/ctor-bench.cs | 67 ++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 mono/benchmark/ctor-bench.cs diff --git a/mono/benchmark/Makefile.am b/mono/benchmark/Makefile.am index 40dfaa5d3c8..4db8e150a63 100644 --- a/mono/benchmark/Makefile.am +++ b/mono/benchmark/Makefile.am @@ -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 index 00000000000..31099acdd55 --- /dev/null +++ b/mono/benchmark/ctor-bench.cs @@ -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); + + } +} + -- 2.25.1