aboutsummaryrefslogtreecommitdiff
path: root/tests/bench/bench_float.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_float.sh
a
Diffstat (limited to 'tests/bench/bench_float.sh')
-rw-r--r--tests/bench/bench_float.sh54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/bench/bench_float.sh b/tests/bench/bench_float.sh
new file mode 100644
index 0000000..794e976
--- /dev/null
+++ b/tests/bench/bench_float.sh
@@ -0,0 +1,54 @@
+#!/bin/bash
+# plain float loop against the same loop lifted by o3. the program is
+# tests/programs/fbench.zc: 'a' is plain, 'b' is o3, and the digits are repetitions.
+# the slope between 1 repetition and N drops startup and compile time, so
+# this does not bootstrap the compiler. each kernel is poly() of 20000,
+# and (int) of one call is 59997.
+cd "$(dirname "$0")/../.."
+T=$(mktemp -d)
+trap 'rm -rf "$T"' EXIT
+gcc -O2 -w -DJTYPE=int src/core/core.c src/core/io_linux.c -Isrc/core -o "$T/zy" || exit 1
+vms=("$T/zy"); names=("interp")
+gcc -O2 -w src/micro/micro.c src/micro/port_linux.c -Isrc/core -Isrc/micro -o "$T/zym" && { vms+=("$T/zym"); names+=("micro"); }
+if command -v llvm-config >/dev/null; then
+ gcc -O2 -w -DJTYPE=int -DZYLLVM $(llvm-config --cflags) src/core/core.c src/core/io_linux.c -Isrc/core -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 src/core/core.c src/core/io_linux.c -Isrc/core -o "$T/zyj" \
+ && { vms+=("qemu-aarch64 $T/zyj"); names+=("arm64"); }
+fi
+src=$(cat tests/programs/fbench.zc)
+# milliseconds per call of kernel $2 (a or b) on vm $1
+per() {
+ python3 - "$1" "$2" "$src" << 'PY'
+import sys, time, subprocess
+vm, which, src = sys.argv[1], sys.argv[2], sys.argv[3].encode()
+def once(arg):
+ t0 = time.perf_counter()
+ p = subprocess.run(vm.split(), input=src + b"`" + arg.encode(), stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
+ return time.perf_counter() - t0, p.returncode, p.stdout
+def best(arg):
+ b, out = 1e9, b""
+ for _ in range(3):
+ d, r, o = once(arg)
+ if r == 0 and d < b:
+ b, out = d, o
+ return b, out
+one, _ = best(which + "1")
+n = 4
+while True:
+ many, out = best("%s%d" % (which, n))
+ if many - one > 0.8 or n >= 1024:
+ break
+ n *= 4
+print("%.3f" % ((many - one) / (n - 1) * 1000))
+print(out.decode().strip(), file=sys.stderr)
+PY
+}
+printf "%-10s %12s %12s %8s\n" backend "plain ms" "o3 ms" speedup
+for i in "${!vms[@]}"; do
+ p=$(per "${vms[$i]}" a)
+ o=$(per "${vms[$i]}" b)
+ printf "%-10s %12s %12s %8s\n" "${names[$i]}" "$p" "$o" "$(python3 -c "print('%.2fx' % ($p / $o) if $o else 'n/a')")"
+done