aboutsummaryrefslogtreecommitdiff
path: root/tests/programs/bench_share.zc
blob: 04306fe2750bd1b8abc7b14a3ee07b4595e6735a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
namespace;
include rt;

// walk one shared spine from two parents. the checksum is one repetition.
fn build() {
	let i = 0, spine = 0;
	while (i < 40) { spine = rt.cons(i, spine); i++; }
	return rt.cons(rt.cons(spine, 1), rt.cons(spine, 2));
}
fn sum(t) {
	let a = 0;
	while (t) { a = a + rt.car(t); t = rt.cdr(t); }
	return a;
}
fn work() {
	let ch = rt.get_c(), reps = 0, acc = 0, root, spine, k;
	while (ch >= '0' && ch <= '9') { reps = reps * 10 + ch - '0'; ch = rt.get_c(); }
	root = build();
	spine = rt.car(rt.car(root));
	while (reps > 0) {
		k = 0;
		acc = 0;
		while (k < 200) { acc = acc + sum(spine); k++; }
		acc = acc + rt.cdr(rt.car(root)) + rt.cdr(rt.cdr(root));
		reps--;
	}
	return acc;
}
fn main() {
	rt.put_n(work());
	rt.put_c(10);
	return 0;
}