From ecc350ca5c2eb50be8309c5f14f8bf0d87db9a02 Mon Sep 17 00:00:00 2001 From: Moon Flower Date: Mon, 12 Oct 2026 08:46:23 +0330 Subject: a --- tests/programs/bench_share.zc | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/programs/bench_share.zc (limited to 'tests/programs/bench_share.zc') diff --git a/tests/programs/bench_share.zc b/tests/programs/bench_share.zc new file mode 100644 index 0000000..6fa478f --- /dev/null +++ b/tests/programs/bench_share.zc @@ -0,0 +1,30 @@ +// walk one shared spine from two parents. the checksum is one repetition. +fn build() { + let i = 0, spine = 0; + while (i < 40) { spine = cons(i, spine); i++; } + return cons(cons(spine, 1), cons(spine, 2)); +} +fn sum(t) { + let a = 0; + while (t) { a = a + car(t); t = cdr(t); } + return a; +} +fn work() { + let ch = get_c(), reps = 0, acc = 0, root, spine, k; + while (ch >= '0' && ch <= '9') { reps = reps * 10 + ch - '0'; ch = get_c(); } + root = build(); + spine = car(car(root)); + while (reps > 0) { + k = 0; + acc = 0; + while (k < 200) { acc = acc + sum(spine); k++; } + acc = acc + cdr(car(root)) + cdr(cdr(root)); + reps--; + } + return acc; +} +fn main() { + put_n(work()); + put_c(10); + return 0; +} -- cgit v1.2.3