Treat CEE_BREAK the same as Debugger:Break (), i.e. route it through sdb.
[mono-project/dkf.git] / mono / mini / bench.cs
blobc6a23620c5676565fe57615b1b48f56beb2a8e2e
1 using System;
2 using System.Reflection;
4 /*
5 * Regression tests for the mono JIT.
7 * Each test needs to be of the form:
9 * static int test_<result>_<name> ();
11 * where <result> is an integer (the value that needs to be returned by
12 * the method to make it pass.
13 * <name> is a user-displayed name used to identify the test.
15 * The tests can be driven in two ways:
16 * *) running the program directly: Main() uses reflection to find and invoke
17 * the test methods (this is useful mostly to check that the tests are correct)
18 * *) with the --regression switch of the jit (this is the preferred way since
19 * all the tests will be run with optimizations on and off)
21 * The reflection logic could be moved to a .dll since we need at least another
22 * regression test file written in IL code to have better control on how
23 * the IL code looks.
26 class Tests {
28 static int Main (string[] args) {
29 return TestDriver.RunTests (typeof (Tests), args);
32 static public int test_0_many_nested_loops () {
33 // we do the loop a few times otherwise it's too fast
34 for (int i = 0; i < 5; ++i) {
35 int n = 16;
36 int x = 0;
37 int a = n;
38 while (a-- != 0) {
39 int b = n;
40 while (b-- != 0) {
41 int c = n;
42 while (c-- != 0) {
43 int d = n;
44 while (d-- != 0) {
45 int e = n;
46 while (e-- != 0) {
47 int f = n;
48 while (f-- != 0) {
49 x++;
56 if (x != 16777216)
57 return 1;
59 return 0;
62 public static int test_0_logic_run ()
64 // GPL: Copyright (C) 2001 Southern Storm Software, Pty Ltd.
65 int iter, i = 0;
67 while (i++ < 10) {
68 // Initialize.
69 bool flag1 = true;
70 bool flag2 = true;
71 bool flag3 = true;
72 bool flag4 = true;
73 bool flag5 = true;
74 bool flag6 = true;
75 bool flag7 = true;
76 bool flag8 = true;
77 bool flag9 = true;
78 bool flag10 = true;
79 bool flag11 = true;
80 bool flag12 = true;
81 bool flag13 = true;
83 // First set of tests.
84 for(iter = 0; iter < 2000000; ++iter) {
85 if((flag1 || flag2) && (flag3 || flag4) &&
86 (flag5 || flag6 || flag7))
88 flag8 = !flag8;
89 flag9 = !flag9;
90 flag10 = !flag10;
91 flag11 = !flag11;
92 flag12 = !flag12;
93 flag13 = !flag13;
94 flag1 = !flag1;
95 flag2 = !flag2;
96 flag3 = !flag3;
97 flag4 = !flag4;
98 flag5 = !flag5;
99 flag6 = !flag6;
100 flag1 = !flag1;
101 flag2 = !flag2;
102 flag3 = !flag3;
103 flag4 = !flag4;
104 flag5 = !flag5;
105 flag6 = !flag6;
109 return 0;
111 static public int test_1028_sieve () {
112 //int NUM = ((argc == 2) ? atoi(argv[1]) : 1);
113 int NUM = 2000;
114 byte[] flags = new byte[8192 + 1];
115 int i, k;
116 int count = 0;
118 while (NUM-- != 0) {
119 count = 0;
120 for (i=2; i <= 8192; i++) {
121 flags[i] = 1;
123 for (i=2; i <= 8192; i++) {
124 if (flags[i] != 0) {
125 // remove all multiples of prime: i
126 for (k=i+i; k <= 8192; k+=i) {
127 flags[k] = 0;
129 count++;
133 //printf("Count: %d\n", count);
134 return(count);
137 public static int fib (int n) {
138 if (n < 2)
139 return 1;
140 return fib(n-2)+fib(n-1);
143 public static int test_3524578_fib () {
144 for (int i = 0; i < 10; i++)
145 fib (32);
147 return fib (32);
150 private static ulong numMoves;
152 static void movetower (int disc, int from, int to, int use) {
153 if (disc > 0) {
154 numMoves++;
155 movetower (disc-1, from, use, to);
156 movetower (disc-1, use, to, from);
160 public static int test_0_hanoi () {
161 int iterations = 5000;
162 int numdiscs = 12;
164 numMoves = 0;
165 while (iterations > 0) {
166 iterations--;
167 movetower (numdiscs, 1, 3, 2);
169 if (numMoves != 20475000)
170 return 1;
171 return 0;
174 public static int test_0_castclass () {
175 object a = "a";
177 for (int i = 0; i < 100000000; i++) {
178 string b = (string)a;
179 if ((object)a != (object)b)
180 return 1;
182 return 0;
185 public static int test_23005000_float () {
186 double a, b, c, d;
187 bool val;
188 int loops = 0;
189 a = 0.0;
190 b = 0.0001;
191 c = 2300.5;
192 d = 1000.0;
194 while (a < c) {
195 if (a == d)
196 b *= 2;
197 a += b;
198 val = b >= c;
199 if (val) break;
200 loops++;
202 return loops;
206 /// Gaussian blur of a generated grayscale picture
207 private int test_0_blur(int size) {
208 const int num = 5; // Number of time to blur
209 byte[,] arr1 = new byte[size, size];
210 byte[,] arr2 = new byte[size, size];
212 int iterations = 1;
214 while(iterations-- > 0) {
216 // Draw fake picture
217 for(int i = 0; i < size; i++) {
218 for(int j = 0; j < size; j++) {
219 arr1[i, j] = (byte) (i%255);
223 for(int n = 0; n < num; n++) { // num rounds of blurring
224 for(int i = 3; i < size-3; i++) // vertical blur arr1 -> arr2
225 for(int j = 0; j < size; j++)
226 arr2[i, j] = (byte)((arr1[i-3, j] + arr1[i+3, j]
227 + 6*(arr1[i-2, j]+arr1[i+2, j])
228 + 15*(arr1[i-1, j]+arr1[i+1, j])
229 + 20*arr1[i, j] + 32)>>6);
231 for(int j = 3; j < size-3; j++) // horizontal blur arr1 -> arr2
232 for(int i = 0; i < size; i++)
233 arr1[i, j] = (byte)((arr2[i, j-3] + arr2[i, j+3]
234 + 6*(arr2[i, j-2]+arr2[i, j+2])
235 + 15*(arr2[i, j-1]+arr2[i, j+1])
236 + 20*arr2[i, j] + 32)>>6);
240 return 0;