jolt/bench/run.sh
Dmitri Sotnikov c13a8ee402
Add benchmark suite for alloc/dispatch/collection workloads (jolt-1r86) (#135)
The ray tracer is float-compute-bound (devirt, alloc removal, type-proving all
measured flat on it), so it can't validate the optimization passes. Add a small
cross-language suite (AWFY + CLBG style, portable Clojure) isolating the axes it
misses:

  binary-trees  allocation / GC pressure (escaping short-lived records)
  dispatch      megamorphic protocol dispatch (~1M dispatches/s; WP can't devirt)
  collections   persistent map/vector churn

bench/run.sh runs them; bench/README.md maps each to the pass it exercises.

collections immediately surfaced jolt-684u: the persistent hash map is O(n) per
assoc (flat copy-on-write bucket array, not a HAMT) — n=4000 assocs take 50s.
Invisible to the ray tracer (no maps).

Co-authored-by: Yogthos <yogthos@gmail.com>
2026-06-16 04:41:49 +00:00

39 lines
1.3 KiB
Bash
Executable file

#!/bin/sh
# Run the jolt benchmark suite and print mean ms per benchmark.
#
# Each benchmark isolates an axis the ray tracer (float-compute-bound) doesn't
# capture — see README.md. Run back-to-back against `main` to measure a pass's
# impact (the same protocol as test/bench/core-bench.janet).
#
# bench/run.sh # default sizes, whole-program optimization on
# JOLT_WHOLE_PROGRAM=0 bench/run.sh # compare with WP off
# bench/run.sh binary-trees # one benchmark
#
# Needs `jolt` on PATH (build with `jpm build`; export PATH="$PWD/build:$PATH").
set -e
cd "$(dirname "$0")"
export JOLT_DIRECT_LINK="${JOLT_DIRECT_LINK:-1}"
export JOLT_WHOLE_PROGRAM="${JOLT_WHOLE_PROGRAM:-1}"
export JOLT_APP_PATHS="$PWD"
export JOLT_PATH="$PWD"
# name:default-arg (arg sized to run in a few seconds each)
# NOTE collections is small because the persistent map is O(n)/assoc (jolt-684u);
# raise it once that's fixed to a HAMT.
BENCHES="binary-trees:14 dispatch:2000 collections:1500"
run_one() {
ns="${1%%:*}"; arg="${2:-${1##*:}}"
printf '%-16s ' "$ns"
jolt -m "$ns" "$arg" 2>&1 | awk '/^mean:/{print}'
}
if [ -n "$1" ]; then
for spec in $BENCHES; do
[ "${spec%%:*}" = "$1" ] && run_one "$spec" "$2"
done
else
echo "jolt benchmark suite (WP=$JOLT_WHOLE_PROGRAM)"
for spec in $BENCHES; do run_one "$spec"; done
fi