aboutsummaryrefslogtreecommitdiff
path: root/tests/bench
diff options
context:
space:
mode:
Diffstat (limited to 'tests/bench')
-rw-r--r--tests/bench/bench_bytes.sh16
-rwxr-xr-xtests/bench/run.py4
-rw-r--r--tests/bench/sieve.zc8
3 files changed, 15 insertions, 13 deletions
diff --git a/tests/bench/bench_bytes.sh b/tests/bench/bench_bytes.sh
index 3287a91..acff074 100644
--- a/tests/bench/bench_bytes.sh
+++ b/tests/bench/bench_bytes.sh
@@ -1,4 +1,5 @@
#!/bin/bash
+set -e
# byte-load loop, timed on a run-only image so the resident compiler is not
# in the process. the slope between 1 repetition and N drops startup.
# prints: backend ms/rep checksum
@@ -6,10 +7,8 @@ cd "$(dirname "$0")/../.."
T=$(mktemp -d)
trap 'rm -rf "$T"' EXIT
gcc -O2 -w src/tools/genmap.c -o "$T/genmap" || exit 1
-"$T/genmap" --preset run -o "$T/run" >/dev/null || exit 1
-cp src/tools/zc0.c src/micro/micro.c src/micro/micro_port.h src/micro/port_linux.c src/core/core.c src/core/io_linux.c src/core/fops.h src/core/bops.h src/core/stack.h "$T/run/"
-gcc -O1 -w "$T/run/zc0.c" -o "$T/zc0" || exit 1
-cat "$T/run/rt.zc" src/runtime/run.zc tests/programs/bench_bytes.zc | "$T/zc0" > "$T/run/genome.h" || exit 1
+GENMAP="$T/genmap" bash src/tools/automap.sh run "$T/run" src/runtime/run.zc tests/programs/bench_bytes.zc >/dev/null || exit 1
+cp src/micro/micro.c src/micro/micro_port.h src/micro/port_linux.c src/core/core.c src/core/io_linux.c src/core/fops.h src/core/bops.h src/core/stack.h "$T/run/"
gcc -O2 -w -DJTYPE=int "$T/run/core.c" "$T/run/io_linux.c" -o "$T/zy" || exit 1
gcc -O2 -w "$T/run/micro.c" "$T/run/port_linux.c" -o "$T/zym" || exit 1
vms=("$T/zy" "$T/zym"); names=("interp" "micro")
@@ -22,12 +21,15 @@ if command -v aarch64-linux-gnu-gcc >/dev/null && command -v qemu-aarch64 >/dev/
&& { vms+=("qemu-aarch64 $T/zyj"); names+=("arm64"); }
fi
# seconds for $2 repetitions on vm $1
-once(){ local s e; s=$(date +%s.%N); printf '%s' "$2" | $1 >/tmp/bench_bytes.out; e=$(date +%s.%N); python3 -c "print($e - $s)"; }
+once(){ python3 -c 'import shlex, statistics, subprocess, sys, time; samples=[]; output=b""; cmd=shlex.split(sys.argv[1]); data=sys.argv[2].encode();
+for _ in range(5):
+ start=time.perf_counter(); p=subprocess.run(cmd, input=data, stdout=subprocess.PIPE); p.check_returncode(); samples.append(time.perf_counter()-start); output=p.stdout
+open("/tmp/bench_bytes.out", "wb").write(output); print(statistics.median(samples))' "$1" "$2"; }
printf "%-10s %12s %s\n" backend "ms/rep" checksum
for i in "${!vms[@]}"; do
one=$(once "${vms[$i]}" 1)
- many=$(once "${vms[$i]}" 40)
- ms=$(python3 -c "print(round(($many - $one) / 39 * 1000, 3))")
+ many=$(once "${vms[$i]}" 1000)
+ ms=$(python3 -c "print(round(($many - $one) / 999 * 1000, 3))")
sum=$(tr -d '\n' < /tmp/bench_bytes.out)
printf "%-10s %12s %s\n" "${names[$i]}" "$ms" "$sum"
done
diff --git a/tests/bench/run.py b/tests/bench/run.py
index 69cb943..cb28b92 100755
--- a/tests/bench/run.py
+++ b/tests/bench/run.py
@@ -260,8 +260,8 @@ def main():
if key not in bins:
continue
add(sieve_rows, label, c_call(bins[key], mode), SIEVE_N)
- add(sieve_rows, "zc interp, plain, bounds-checked []int", zc_call(vms["interp"], sieve_src, "a"), SIEVE_N)
- add(sieve_rows, "zc interp, o3, bounds-checked []int", zc_call(vms["interp"], sieve_src, "b"), SIEVE_N)
+ add(sieve_rows, "zc interp, plain, bounds-checked int[?]", zc_call(vms["interp"], sieve_src, "a"), SIEVE_N)
+ add(sieve_rows, "zc interp, o3, bounds-checked int[?]", zc_call(vms["interp"], sieve_src, "b"), SIEVE_N)
add(sieve_rows, "zc interp, o3, raw *int", zc_call(vms["interp"], sieve_src, "c"), SIEVE_N)
if "llvm" in vms:
hot = {"ZYHOT": "1"}
diff --git a/tests/bench/sieve.zc b/tests/bench/sieve.zc
index 1fb579b..9259bf4 100644
--- a/tests/bench/sieve.zc
+++ b/tests/bench/sieve.zc
@@ -1,11 +1,11 @@
// primes below N. the same loops as tests/bench/sieve.c: one word per flag,
// marks start at i*i. the count is 9592.
-// a fixed []int, bounds-checked, plain bytecode
+// a fixed int[?], bounds-checked, plain bytecode
// b the same function lifted by o3
// c o3 through a raw *int, no per-index check
const int N = 100000;
-int sieve(fixed []int f) {
+int sieve(fixed int[?] f) {
int n = len(f), c = 0;
for (int i = 2; i < n; i++) f[i] = 1;
for (int i = 2; i * i < n; i++)
@@ -13,7 +13,7 @@ int sieve(fixed []int f) {
for (int i = 2; i < n; i++) c += f[i];
return c;
}
-o3 int sieve3(fixed []int f) {
+o3 int sieve3(fixed int[?] f) {
int n = len(f), c = 0;
for (int i = 2; i < n; i++) f[i] = 1;
for (int i = 2; i * i < n; i++)
@@ -39,7 +39,7 @@ int main() {
free(d*raw);
return 0;
}
- fixed []int f = new(fixed []int, N);
+ fixed int[?] f = new(fixed int[?], N);
while (reps > 0) {
if (which == 'b') r = sieve3(f);
else r = sieve(f);