2009-03-11 Zoltan Varga <vargaz@gmail.com>
[mono-debugger.git] / mono / benchmark / valuetype-hash-equals.cs
blob2aa1a4ba324d00a513db3a7f690f7fa755f70b3f
1 using System;
3 public class ValueType1
5 static int Main ()
7 Blah a = new Blah ("abc", 1);
8 Blah b = new Blah ("ab" + 'c', 1);
9 long start, end;
10 start = Environment.TickCount;
12 start = Environment.TickCount;
13 for (int i = 0; i < 1000000; i++)
14 a.GetHashCode ();
15 end = Environment.TickCount;
16 Console.WriteLine ("struct common GetHashCode(): {0}", end-start);
18 start = Environment.TickCount;
19 for (int i = 0; i < 1000000; i++)
20 a.Equals (b);
21 end = Environment.TickCount;
22 Console.WriteLine ("struct common Equals(): {0}", end-start);
24 Blah2 a2 = new Blah2 ("abc", 1);
25 Blah2 b2 = new Blah2 ("abc", 1);
26 start = Environment.TickCount;
27 for (int i = 0; i < 1000000; i++)
28 a2.GetHashCode ();
29 end = Environment.TickCount;
30 Console.WriteLine ("struct specific GetHashCode(): {0}", end-start);
32 start = Environment.TickCount;
33 for (int i = 0; i < 1000000; i++)
34 a2.Equals (b2);
35 end = Environment.TickCount;
36 Console.WriteLine ("struct specific Equals(): {0}", end-start);
38 return 0;
41 struct Blah
43 public string s;
44 public int i;
46 public Blah (string s, int k)
48 this.s = s;
49 i = k;
53 struct Blah2
55 public string s;
56 public int i;
58 public Blah2 (string s, int k)
60 this.s = s;
61 i = k;
64 public override int GetHashCode () {
65 return i ^ s.GetHashCode ();
67 public override bool Equals (object obj) {
68 if (obj == null || !(obj is Blah2))
69 return false;
70 Blah2 b = (Blah2)obj;
71 return b.s == this.s && b.i == this.i;