aboutsummaryrefslogtreecommitdiff
path: root/tests/bench/bench_share.sh
diff options
context:
space:
mode:
authorGravatar Moon Flower <moonflower@elhenney.local> 2026-10-12 08:46:23 +0330
committerGravatar Moon Flower <moonflower@elhenney.local> 2026-10-12 08:46:23 +0330
commitecc350ca5c2eb50be8309c5f14f8bf0d87db9a02 (patch)
tree70e0af76a1b13affff7c6cc8aac7b3e6ef960478 /tests/bench/bench_share.sh
a
Diffstat (limited to 'tests/bench/bench_share.sh')
-rw-r--r--tests/bench/bench_share.sh32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/bench/bench_share.sh b/tests/bench/bench_share.sh
new file mode 100644
index 0000000..b449e09
--- /dev/null
+++ b/tests/bench/bench_share.sh
@@ -0,0 +1,32 @@
+#!/bin/bash
+# walk a shared cons spine from two parents, 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
+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_share.zc | "$T/zc0" > "$T/run/genome.h" || exit 1
+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")
+if command -v llvm-config >/dev/null; then
+ gcc -O2 -w -DJTYPE=int -DZYLLVM $(llvm-config --cflags) "$T/run/core.c" "$T/run/io_linux.c" -o "$T/zyl" $(llvm-config --ldflags --libs) \
+ && { vms+=("$T/zyl"); names+=("llvm"); }
+fi
+if command -v aarch64-linux-gnu-gcc >/dev/null && command -v qemu-aarch64 >/dev/null; then
+ aarch64-linux-gnu-gcc -O2 -w -DJTYPE=int -static "$T/run/core.c" "$T/run/io_linux.c" -o "$T/zyj" \
+ && { vms+=("qemu-aarch64 $T/zyj"); names+=("arm64"); }
+fi
+once(){ local s e; s=$(date +%s.%N); printf '%s' "$2" | $1 >/tmp/bench_share.out; e=$(date +%s.%N); python3 -c "print($e - $s)"; }
+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))")
+ sum=$(tr -d '\n' < /tmp/bench_share.out)
+ printf "%-10s %12s %s\n" "${names[$i]}" "$ms" "$sum"
+done