use Paolo's benchmark
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Mon, 17 Nov 2003 18:08:40 +0000 (18:08 -0000)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Mon, 17 Nov 2003 18:08:40 +0000 (18:08 -0000)
svn path=/trunk/mono/; revision=20123

mono/benchmark/Makefile.am
mono/benchmark/valuetype-hash-equals.cs [new file with mode: 0644]
mono/benchmark/valuetype1.cs [deleted file]
mono/benchmark/valuetype2.cs [deleted file]
mono/benchmark/valuetype3.cs [deleted file]

index f13667b988021cb726ddc3ce1454e512d27f3157..4273a7d134df7fe148b428e399f2f1cae5ef44a7 100644 (file)
@@ -25,9 +25,7 @@ TESTSRC=                      \
        bulkcpy.il              \
        math.cs                 \
        boxtest.cs              \
-       valuetype1.cs           \
-       valuetype2.cs           \
-       valuetype3.cs
+       valuetype-hash-equals.cs
 
 TESTSI_TMP=$(TESTSRC:.cs=.exe)
 TESTSI=$(TESTSI_TMP:.il=.exe)
diff --git a/mono/benchmark/valuetype-hash-equals.cs b/mono/benchmark/valuetype-hash-equals.cs
new file mode 100644 (file)
index 0000000..2aa1a4b
--- /dev/null
@@ -0,0 +1,75 @@
+using System;
+
+public class ValueType1
+{
+       static int Main ()
+       {
+               Blah a = new Blah ("abc", 1);
+               Blah b = new Blah ("ab" + 'c', 1);
+               long start, end;
+               start = Environment.TickCount;
+
+               start = Environment.TickCount;
+               for (int i = 0; i < 1000000; i++)
+                       a.GetHashCode ();
+               end = Environment.TickCount;
+               Console.WriteLine ("struct common GetHashCode(): {0}", end-start);
+
+               start = Environment.TickCount;
+               for (int i = 0; i < 1000000; i++)
+                       a.Equals (b);
+               end = Environment.TickCount;
+               Console.WriteLine ("struct common Equals(): {0}", end-start);
+
+               Blah2 a2 = new Blah2 ("abc", 1);
+               Blah2 b2 = new Blah2 ("abc", 1);
+               start = Environment.TickCount;
+               for (int i = 0; i < 1000000; i++)
+                       a2.GetHashCode ();
+               end = Environment.TickCount;
+               Console.WriteLine ("struct specific GetHashCode(): {0}", end-start);
+
+               start = Environment.TickCount;
+               for (int i = 0; i < 1000000; i++)
+                       a2.Equals (b2);
+               end = Environment.TickCount;
+               Console.WriteLine ("struct specific Equals(): {0}", end-start);
+
+               return 0;
+       }
+
+       struct Blah
+       { 
+               public string s;
+               public int i;
+
+               public Blah (string s, int k)
+               {
+                       this.s = s;
+                       i = k;
+               }
+       }
+
+       struct Blah2
+       { 
+               public string s;
+               public int i;
+
+               public Blah2 (string s, int k)
+               {
+                       this.s = s;
+                       i = k;
+               }
+
+               public override int GetHashCode () {
+                       return i ^ s.GetHashCode ();
+               }
+               public override bool Equals (object obj) {
+                       if (obj == null || !(obj is Blah2))
+                               return false;
+                       Blah2 b = (Blah2)obj;
+                       return b.s == this.s && b.i == this.i;
+               }
+       }
+}
+
diff --git a/mono/benchmark/valuetype1.cs b/mono/benchmark/valuetype1.cs
deleted file mode 100644 (file)
index 1fbbbdf..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-using System;
-
-public class ValueType1
-{
-       static int Main ()
-       {
-               Blah a = new Blah ("abc", 1);
-
-               for (int i = 0; i < 1000000; i++)
-                       a.GetHashCode ();
-
-               return 0;
-       }
-
-       struct Blah
-       { 
-               public string s;
-               public int i;
-
-               public Blah (string s, int k)
-               {
-                       this.s = s;
-                       i = k;
-               }
-       }
-}
-
diff --git a/mono/benchmark/valuetype2.cs b/mono/benchmark/valuetype2.cs
deleted file mode 100644 (file)
index e07d964..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-using System;
-
-public class ValueType2
-{
-       static int Main ()
-       {
-               Blah a = new Blah ("abc", 1);
-               Blah b = new Blah (string.Format ("ab{0}", 'c'), 1);
-
-               for (int i = 0; i < 1000000; i++)
-                       a.Equals (b);
-
-               return 0;
-       }
-
-       struct Blah
-       { 
-               public string s;
-               public int i;
-
-               public Blah (string s, int k)
-               {
-                       this.s = s;
-                       i = k;
-               }
-       }
-}
-
diff --git a/mono/benchmark/valuetype3.cs b/mono/benchmark/valuetype3.cs
deleted file mode 100644 (file)
index f92ea18..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-using System;
-
-public class ValueType2
-{
-       static int Main ()
-       {
-               Blah a = new Blah ("abc", 1);
-               Blah b = new Blah (string.Format ("ab{0}", 'c'), 2);
-
-               for (int i = 0; i < 1000000; i++)
-                       a.Equals (b);
-
-               return 0;
-       }
-
-       struct Blah
-       { 
-               public string s;
-               public int i;
-
-               public Blah (string s, int k)
-               {
-                       this.s = s;
-                       i = k;
-               }
-       }
-}
-