diff options
| author | 2026-10-14 16:53:22 +0330 | |
|---|---|---|
| committer | 2026-10-14 16:53:22 +0330 | |
| commit | 58b86428cee46268002d23fd985a1813f641115c (patch) | |
| tree | 43bfaeb65d1ab096d47f511577a4ff9c50919305 /tests/bench/sweep.zc | |
| parent | merge work/xref: zc0 u*d redo and follow-ups (diff) | |
wip: bench suite
Diffstat (limited to 'tests/bench/sweep.zc')
| -rw-r--r-- | tests/bench/sweep.zc | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/bench/sweep.zc b/tests/bench/sweep.zc new file mode 100644 index 0000000..9bc7070 --- /dev/null +++ b/tests/bench/sweep.zc @@ -0,0 +1,23 @@ +namespace; +include rt; + +// a 256-word sweep through a heap pointer, with bounds checks (the default) and without +// (unbounded): each pass adds every word of the block 1000 times. the index is variable +// and the block is reached through a pointer, so the checked version keeps its checks. +// input: a letter (c checked, u unbounded, z none) and how many times to run it. +int sweep(int* p, int n) { int s = 0; for (int k = 0; k < 1000; k++) for (int i = 0; i < n; i++) s = s + p[i]; return s; } +unbounded int sweepu(int* p, int n) { int s = 0; for (int k = 0; k < 1000; k++) for (int i = 0; i < n; i++) s = s + p[i]; return s; } +fn main() { + int* p = rt.new(256); + for (int i = 0; i < 256; i++) p[i] = i; + let which = rt.get_c(), reps = 0, ch = rt.get_c(), r = 0; + while (ch >= '0' && ch <= '9') { reps = reps * 10 + ch - '0'; ch = rt.get_c(); } + while (reps > 0) { + if (which == 'c') r = sweep(p, 256); + if (which == 'u') r = sweepu(p, 256); + reps--; + } + rt.put_n(r); rt.put_c(10); + rt.free(p); + return 0; +} |
