aboutsummaryrefslogtreecommitdiff
path: root/docs/history/15-o3/code/bench.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 /docs/history/15-o3/code/bench.sh
a
Diffstat (limited to 'docs/history/15-o3/code/bench.sh')
-rwxr-xr-xdocs/history/15-o3/code/bench.sh26
1 files changed, 26 insertions, 0 deletions
diff --git a/docs/history/15-o3/code/bench.sh b/docs/history/15-o3/code/bench.sh
new file mode 100755
index 0000000..c5e5a83
--- /dev/null
+++ b/docs/history/15-o3/code/bench.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+# o3 against plain code: each kernel in tests/bench.zc on each backend, with
+# the time to start up and compile (the 'z' run) taken off. needs bc.
+cd "$(dirname "$0")"; T=$(mktemp -d); trap 'rm -rf $T' EXIT
+gcc -O2 -w -DJTYPE=int core.c io_linux.c -o $T/zy
+vms=("$T/zy"); names=("interp")
+if command -v llvm-config >/dev/null; then
+ gcc -O2 -w -DJTYPE=int -DZYLLVM $(llvm-config --cflags) core.c 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 core.c io_linux.c -o $T/zyj && { vms+=("qemu-aarch64 $T/zyj"); names+=("arm64 (qemu)"); }
+fi
+# seconds per run of kernel $2 on vm $1: the slope between $3 runs and 1 run,
+# best of three each, so starting up and compiling cancel out
+t(){ local s e; s=$(date +%s.%N); (cat tests/bench.zc; printf '`'$2$3) | $1 >/dev/null; e=$(date +%s.%N); echo "$e - $s" | bc; }
+best(){ local b=999 x i; for i in 1 2 3; do x=$(t "$1" $2 $3); b=$(echo "if ($x < $b) $x else $b" | bc); done; echo $b; }
+per(){ echo "scale=5; ($(best "$1" $2 $3) - $(best "$1" $2 1)) / ($3 - 1)" | bc; }
+printf "%-14s %-8s %10s %10s %8s\n" backend kernel "plain ms" "o3 ms" speedup
+for i in "${!vms[@]}"; do
+ n=41; [ "${names[$i]}" = interp ] && n=5
+ for k in "collatz a b" "sieve c d" "digits e f" "fib g h"; do
+ set -- $k
+ p=$(per "${vms[$i]}" $2 5); o=$(per "${vms[$i]}" $3 $n)
+ printf "%-14s %-8s %10.2f %10.2f %7.1fx\n" "${names[$i]}" $1 $(echo "$p * 1000" | bc) $(echo "$o * 1000" | bc) $(echo "scale=2; $p / $o" | bc)
+ done
+done