tock-mirror/testcases/commstime.rain

99 lines
1.2 KiB
Plaintext

process prefix_int(int: pre, ?int: in, !int: out)
{
out ! pre;
while (true)
{
int: n;
in ? n;
out ! n;
}
}
process succ_int(?int: in,!int : out)
{
while (true)
{
int: n;
in ? n;
out ! n + 1;
}
}
process seq_delta2_int(?int: in, !int: out0, !int: out1)
{
while (true)
{
int: n;
in ? n;
out0 ! n;
out1 ! n;
}
}
function [uint8] : int_to_str(int: src)
{
int: x;
[uint8]: r;
x = src;
while (x > 0)
{
r = ['0' + (uint8: x % 10)] + r;
x /= 10;
}
return r;
}
process out_str(!uint8: out, [uint8]: val)
{
seqeach (c : val)
{
out ! c;
}
}
process consume_int(?int: in, !uint8: out) ### uses (time)
{
### Warm-up:
seqeach (n : [1..100])
{
int: _x;
in ? _x;
}
while (true)
{
int: n;
time: t0,t1;
n = 0;
now t0;
while (n < 1000000)
{
int: _x;
in ? _x;
n += 1;
}
now t1;
int: m;
m = toNanos(t1 - t0) / 1000000;
run out_str(out, "Time per commstime iteration in nano-seconds: "
+ int_to_str(m) + "\n");
}
}
process main(!uint8: out)
{
channel int: c,d,e,f;
par
{
run prefix_int(0,?c,!d);
run seq_delta2_int(?d,!e,!f);
run succ_int(?e,!c);
run consume_int(?f,out);
}
}