diff options
Diffstat (limited to 'docs/history/15-o3/code/tests/bench.zc')
| -rw-r--r-- | docs/history/15-o3/code/tests/bench.zc | 30 |
1 files changed, 0 insertions, 30 deletions
diff --git a/docs/history/15-o3/code/tests/bench.zc b/docs/history/15-o3/code/tests/bench.zc deleted file mode 100644 index a7e53f5..0000000 --- a/docs/history/15-o3/code/tests/bench.zc +++ /dev/null @@ -1,30 +0,0 @@ -// four kernels with and without o3; bench.sh runs each one on each backend -int csum(int lim) { int s = 0; for (int n = 1; n < lim; n++) { int x = n; while (x != 1) { if (x & 1) x = 3 * x + 1; else x = x / 2; s++; } } return s; } -o3 int csum3(int lim) { int s = 0; for (int n = 1; n < lim; n++) { int x = n; while (x != 1) { if (x & 1) x = 3 * x + 1; else x = x / 2; s++; } } return s; } -int sieve(fixed []int f) { int c = 0, n = len(f); for (int i = 0; i < n; i++) f[i] = 1; for (int i = 2; i < n; i++) if (f[i]) { c++; for (int j = i + i; j < n; j += i) f[j] = 0; } return c; } -o3 int sieve3(fixed []int f) { int c = 0, n = len(f); for (int i = 0; i < n; i++) f[i] = 1; for (int i = 2; i < n; i++) if (f[i]) { c++; for (int j = i + i; j < n; j += i) f[j] = 0; } return c; } -int digits(int n) { int s = 0; for (int i = 0; i < n; i++) { int x = i; while (x) { s = s + x % 10; x = x / 10; } } return s; } -o3 int digits3(int n) { int s = 0; for (int i = 0; i < n; i++) { int x = i; while (x) { s = s + x % 10; x = x / 10; } } return s; } -int fib(int n) { if (n < 2) return n; return fib(n - 1) + fib(n - 2); } -o3 int fib3(int n) { if (n < 2) return n; return fib3(n - 1) + fib3(n - 2); } -// input: a letter (the kernel; z runs none) and how many times to run it -fn main() -{ - fixed []int f = new(fixed []int, 50000); - let which = getc(), reps = 0, ch = getc(), r = 0; - while (ch >= '0' && ch <= '9') { reps = reps * 10 + ch - '0'; ch = getc(); } - while (reps > 0) { - if (which == 'a') r = csum(30000); - if (which == 'b') r = csum3(30000); - if (which == 'c') r = sieve(f); - if (which == 'd') r = sieve3(f); - if (which == 'e') r = digits(300000); - if (which == 'f') r = digits3(300000); - if (which == 'g') r = fib(22); - if (which == 'h') r = fib3(22); - reps--; - } - putn(r); putc(10); - free(d*f); - return 0; -} |
