some nice little micro-benchmarks
authorBen Maurer <benm@mono-cvs.ximian.com>
Sat, 1 May 2004 23:39:27 +0000 (23:39 -0000)
committerBen Maurer <benm@mono-cvs.ximian.com>
Sat, 1 May 2004 23:39:27 +0000 (23:39 -0000)
svn path=/trunk/mono/; revision=26540

mono/benchmark/Makefile.am
mono/benchmark/commute.cs [new file with mode: 0644]
mono/benchmark/iconst-byte.cs [new file with mode: 0644]
mono/benchmark/inline-readonly.cs [new file with mode: 0644]
mono/benchmark/readonly-byte-array.cs [new file with mode: 0644]
mono/benchmark/readonly-inst.cs [new file with mode: 0644]
mono/benchmark/readonly-vt.cs [new file with mode: 0644]
mono/benchmark/vt2.cs [new file with mode: 0644]

index 9ec4319b5eddb4a5afd53629df29f543c7391576..10217ab9f84b2e7d1bccd9bf46d52436412c866d 100644 (file)
@@ -8,15 +8,18 @@ TESTSRC=                      \
        fib.cs                  \
        life.cs                 \
        castclass.cs            \
+       commute.cs              \
        isinst.cs               \
        sbperf1.cs              \
        sbperf2.cs              \
+       iconst-byte.cs          \
        inline1.cs              \
        inline2.cs              \
        inline3.cs              \
        inline4.cs              \
        inline5.cs              \
        inline6.cs              \
+       inline-readonly.cs      \
        muldiv.cs               \
        loops.cs                \
        initlocals.cs           \
@@ -24,10 +27,14 @@ TESTSRC=                    \
        switch.cs               \
        ctor-bench.cs           \
        readonly.cs             \
+       readonly-byte-array.cs  \
+       readonly-inst.cs        \
+       readonly-vt.cs          \
        bulkcpy.il              \
        math.cs                 \
        boxtest.cs              \
-       valuetype-hash-equals.cs
+       valuetype-hash-equals.cs \
+       vt2.cs
 
 TESTSI_TMP=$(TESTSRC:.cs=.exe)
 TESTSI=$(TESTSI_TMP:.il=.exe)
diff --git a/mono/benchmark/commute.cs b/mono/benchmark/commute.cs
new file mode 100644 (file)
index 0000000..00dff80
--- /dev/null
@@ -0,0 +1,37 @@
+using System;
+
+class A {
+       static int Main ()
+       {
+               int a = 0;
+               
+               for (int i = 0; i < 50000000; i++) {
+                       
+                       
+                       a = 
+                               (((((a + 1) - 2) + 3) - 4 + 5 - 6 + 7) +
+                               (((((a + 1) - 2) + 3) - 4 + 5 - 6 + 7) +
+                               (((((a + 1) - 2) + 3) - 4 + 5 - 6 + 7) +
+                               (((((a + 1) - 2) + 3) - 4 + 5 - 6 + 7) +
+                               (((((a + 1) - 2) + 3) - 4 + 5 - 6 + 7) +
+                               (((((a + 1) - 2) + 3) - 4 + 5 - 6 + 7) +
+                               (((((a + 1) - 2) + 3) - 4 + 5 - 6 + 7) +
+                               (((((a + 1) - 2) + 3) - 4 + 5 - 6 + 7) +
+                               (((((a + 1) - 2) + 3) - 4 + 5 - 6 + 7) +
+                               (((((a + 1) - 2) + 3) - 4 + 5 - 6 + 7) +
+                               (((((a + 1) - 2) + 3) - 4 + 5 - 6 + 7) +
+                               (((((a + 1) - 2) + 3) - 4 + 5 - 6 + 7) +
+                               (((((a + 1) - 2) + 3) - 4 + 5 - 6 + 7) +
+                               (((((a + 1) - 2) + 3) - 4 + 5 - 6 + 7) +
+                               (((((a + 1) - 2) + 3) - 4 + 5 - 6 + 7) +
+                               (((((a + 1) - 2) + 3) - 4 + 5 - 6 + 7) +
+                               (((((a + 1) - 2) + 3) - 4 + 5 - 6 + 7) +
+                               (((((a + 1) - 2) + 3) - 4 + 5 - 6 + 7)))))))))))))))))));
+               }
+               
+               // no ssa
+               return a != (a + 1) ? 0 : 1;
+       }
+       
+       static void Foo (out int dummy) { dummy = 0; }
+}
\ No newline at end of file
diff --git a/mono/benchmark/iconst-byte.cs b/mono/benchmark/iconst-byte.cs
new file mode 100644 (file)
index 0000000..05178ad
--- /dev/null
@@ -0,0 +1,41 @@
+using System;
+
+class A {
+       static int Main ()
+       {
+               // prevent ssa (for now)
+               int dummy;
+               Foo (out dummy);
+               
+               for (int i = 0; i < 50000000; i++) {
+                       byte b;
+                       
+                       b = 0;
+                       b = 0;
+                       b = 0;
+                       b = 0;
+                       b = 0;
+                       b = 0;
+                       b = 0;
+                       b = 0;
+                       b = 0;
+                       b = 0;
+                       b = 0;
+                       b = 0;
+                       b = 0;
+                       b = 0;
+                       b = 0;
+                       b = 0;
+                       b = 0;
+                       b = 0;
+                       b = 0;
+                       b = 0;
+                       b = 0;
+                       b = 0;
+               }
+               
+               return 0;
+       }
+       
+       static void Foo (out int dummy) { dummy = 0; }
+}
\ No newline at end of file
diff --git a/mono/benchmark/inline-readonly.cs b/mono/benchmark/inline-readonly.cs
new file mode 100644 (file)
index 0000000..df610ee
--- /dev/null
@@ -0,0 +1,17 @@
+using System;
+
+public class A {
+       
+       static readonly A a = new A ();
+       
+       static int Main ()
+       {       
+               for (int i = 0; i < 500000000; i++)
+                       a.Dummy ();
+               
+               return 0;
+       }
+       
+       public virtual void Dummy () {
+       }
+}
\ No newline at end of file
diff --git a/mono/benchmark/readonly-byte-array.cs b/mono/benchmark/readonly-byte-array.cs
new file mode 100644 (file)
index 0000000..6af67b3
--- /dev/null
@@ -0,0 +1,30 @@
+class Foo {
+       static readonly byte [] my_table = {
+               0x00, 0x03, 0x06, 0x05, 0x0C, 0x0F, 0x0A, 0x09, 0x18, 0x1B, 0x1E, 0x1D, 0x14, 0x17, 0x12, 0x11, 
+               0x30, 0x33, 0x36, 0x35, 0x3C, 0x3F, 0x3A, 0x39, 0x28, 0x2B, 0x2E, 0x2D, 0x24, 0x27, 0x22, 0x21, 
+               0x60, 0x63, 0x66, 0x65, 0x6C, 0x6F, 0x6A, 0x69, 0x78, 0x7B, 0x7E, 0x7D, 0x74, 0x77, 0x72, 0x71, 
+               0x50, 0x53, 0x56, 0x55, 0x5C, 0x5F, 0x5A, 0x59, 0x48, 0x4B, 0x4E, 0x4D, 0x44, 0x47, 0x42, 0x41, 
+               0xC0, 0xC3, 0xC6, 0xC5, 0xCC, 0xCF, 0xCA, 0xC9, 0xD8, 0xDB, 0xDE, 0xDD, 0xD4, 0xD7, 0xD2, 0xD1, 
+               0xF0, 0xF3, 0xF6, 0xF5, 0xFC, 0xFF, 0xFA, 0xF9, 0xE8, 0xEB, 0xEE, 0xED, 0xE4, 0xE7, 0xE2, 0xE1, 
+               0xA0, 0xA3, 0xA6, 0xA5, 0xAC, 0xAF, 0xAA, 0xA9, 0xB8, 0xBB, 0xBE, 0xBD, 0xB4, 0xB7, 0xB2, 0xB1, 
+               0x90, 0x93, 0x96, 0x95, 0x9C, 0x9F, 0x9A, 0x99, 0x88, 0x8B, 0x8E, 0x8D, 0x84, 0x87, 0x82, 0x81, 
+               0x9B, 0x98, 0x9D, 0x9E, 0x97, 0x94, 0x91, 0x92, 0x83, 0x80, 0x85, 0x86, 0x8F, 0x8C, 0x89, 0x8A, 
+               0xAB, 0xA8, 0xAD, 0xAE, 0xA7, 0xA4, 0xA1, 0xA2, 0xB3, 0xB0, 0xB5, 0xB6, 0xBF, 0xBC, 0xB9, 0xBA, 
+               0xFB, 0xF8, 0xFD, 0xFE, 0xF7, 0xF4, 0xF1, 0xF2, 0xE3, 0xE0, 0xE5, 0xE6, 0xEF, 0xEC, 0xE9, 0xEA, 
+               0xCB, 0xC8, 0xCD, 0xCE, 0xC7, 0xC4, 0xC1, 0xC2, 0xD3, 0xD0, 0xD5, 0xD6, 0xDF, 0xDC, 0xD9, 0xDA, 
+               0x5B, 0x58, 0x5D, 0x5E, 0x57, 0x54, 0x51, 0x52, 0x43, 0x40, 0x45, 0x46, 0x4F, 0x4C, 0x49, 0x4A, 
+               0x6B, 0x68, 0x6D, 0x6E, 0x67, 0x64, 0x61, 0x62, 0x73, 0x70, 0x75, 0x76, 0x7F, 0x7C, 0x79, 0x7A, 
+               0x3B, 0x38, 0x3D, 0x3E, 0x37, 0x34, 0x31, 0x32, 0x23, 0x20, 0x25, 0x26, 0x2F, 0x2C, 0x29, 0x2A, 
+               0x0B, 0x08, 0x0D, 0x0E, 0x07, 0x04, 0x01, 0x02, 0x13, 0x10, 0x15, 0x16, 0x1F, 0x1C, 0x19, 0x1A 
+       };
+       
+       static void Main ()
+       {
+               byte b = 0;
+               byte foo = 0;
+               for (int i = 0; i < 100000000; i ++, b ++) {
+                       foo ^= my_table [b];
+                       foo ^= my_table [foo];
+               }
+       }
+}
\ No newline at end of file
diff --git a/mono/benchmark/readonly-inst.cs b/mono/benchmark/readonly-inst.cs
new file mode 100644 (file)
index 0000000..ec257d9
--- /dev/null
@@ -0,0 +1,23 @@
+using System;
+
+class A {
+       class B { public readonly C c = new C (); }
+       class C { public readonly D d = new D (); }
+       class D { public readonly E e = new E (); }
+       class E { public readonly int i = 1; }
+       
+       static readonly A foo = new A ();
+       static readonly A bar = new A ();
+       
+       readonly B b = new B ();
+       static int Main ()
+       {
+       
+               for (int i = 0; i < 50000000; i++) {
+                       if (foo.b.c.d.e.i != bar.b.c.d.e.i)
+                               return 1;
+               }
+               
+               return 0;
+       }
+}
\ No newline at end of file
diff --git a/mono/benchmark/readonly-vt.cs b/mono/benchmark/readonly-vt.cs
new file mode 100644 (file)
index 0000000..127724b
--- /dev/null
@@ -0,0 +1,22 @@
+// Since the structs are readonly, the expression here is a jit time constant.
+
+using System;
+
+struct A {
+       struct B { int dummy; public C c; }
+       struct C { int dummy; public D d; }
+       struct D { public int i; }
+       
+       static readonly B b, bb;
+       
+       static int Main ()
+       {
+       
+               for (int i = 0; i < 50000000; i++) {
+                       if (b.c.d.i != bb.c.d.i)
+                               return 1;
+               }
+               
+               return 0;
+       }
+}
\ No newline at end of file
diff --git a/mono/benchmark/vt2.cs b/mono/benchmark/vt2.cs
new file mode 100644 (file)
index 0000000..295e724
--- /dev/null
@@ -0,0 +1,26 @@
+using System;
+
+public struct A {
+       public int a;
+       static int Main ()
+       {
+               A a = new A ();
+               A b = new A ();
+               
+               for (int i = 0; i < 50000000; i++) {
+                       a.a = i;
+                       b.a = i + 5;
+
+                       a.a = Foo (a, b);
+                       b.a = a.a + 8;
+                       
+                       Foo (a, b);
+               }
+               
+               return 0;
+       }
+       
+       static int Foo (A a, A b) {
+               return a.a + b.a;
+       }
+}
\ No newline at end of file