oxedyne/fe2o3/fe2o3_austenite/tools/bench/speed_bench.sh
2.6 KiB, 1 run, executable
created by r1870400018:60951, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | #!/usr/bin/env bash |
| 2 | # S0 native speed bench: typst compile -j16, typst compile -j1 and the native |
| 3 | # austenite binary, interleaved run-for-run across engines so host load hits |
| 4 | # every engine equally, each run capped at 3G and timed under |
| 5 | # `/usr/bin/time -v`. See tools/bench/README.md for the full protocol and the |
| 6 | # owner-decision pass line this feeds. |
| 7 | set -uo pipefail |
| 8 | |
| 9 | HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 10 | # shellcheck source=lib/host.sh |
| 11 | source "$HERE/lib/host.sh" |
| 12 | |
| 13 | AUSTENITE_BIN="${AUSTENITE_BIN:?set AUSTENITE_BIN to the built austenite binary}" |
| 14 | TYPST_BIN="${TYPST_BIN:-typst}" |
| 15 | WARMUPS="${WARMUPS:-1}" |
| 16 | RUNS="${RUNS:-3}" |
| 17 | OUT_DIR="${OUT_DIR:?set OUT_DIR}" |
| 18 | DOCS=("$@") |
| 19 | |
| 20 | if [[ ${#DOCS[@]} -eq 0 ]]; then |
| 21 | echo "usage: OUT_DIR=... AUSTENITE_BIN=... speed_bench.sh <doc.typ>..." >&2 |
| 22 | exit 2 |
| 23 | fi |
| 24 | |
| 25 | mkdir -p "$OUT_DIR" |
| 26 | JSONL="$OUT_DIR/native_runs.jsonl" |
| 27 | : > "$JSONL" |
| 28 | |
| 29 | # The --timings flag is a U9 addendum not yet landed -- detect it from the |
| 30 | # source rather than probing the binary, because austenite's argument parser |
| 31 | # treats an unrecognised flag as a positional path (see bin/austenite.rs), |
| 32 | # which would silently break the invocation rather than error cleanly. |
| 33 | AUSTENITE_SRC="$HERE/../../src/bin/austenite.rs" |
| 34 | HAS_TIMINGS=false |
| 35 | if [[ -f "$AUSTENITE_SRC" ]] && grep -q -- '--timings' "$AUSTENITE_SRC"; then |
| 36 | HAS_TIMINGS=true |
| 37 | fi |
| 38 | echo "[speed_bench] austenite --timings: $HAS_TIMINGS (U9 addendum)" >&2 |
| 39 | |
| 40 | engines_for_doc() { |
| 41 | local doc="$1" scratch="$2" |
| 42 | # name|jobs|command... |
| 43 | echo "typst-j16|16|$TYPST_BIN compile -j 16 $doc $scratch/typst-j16.pdf" |
| 44 | echo "typst-j1|1|$TYPST_BIN compile -j 1 $doc $scratch/typst-j1.pdf" |
| 45 | local aust_cmd=("$AUSTENITE_BIN") |
| 46 | if $HAS_TIMINGS; then |
| 47 | aust_cmd+=(--timings) |
| 48 | fi |
| 49 | aust_cmd+=("$doc" "$scratch/austenite-out") |
| 50 | echo "austenite-native|1|${aust_cmd[*]}" |
| 51 | } |
| 52 | |
| 53 | for doc in "${DOCS[@]}"; do |
| 54 | docname="$(basename "$doc" .typ)" |
| 55 | scratch="$OUT_DIR/scratch/$docname" |
| 56 | mkdir -p "$scratch" |
| 57 | mapfile -t engines < <(engines_for_doc "$doc" "$scratch") |
| 58 | |
| 59 | # Warm-ups: one pass per engine, not recorded. |
| 60 | for ((w = 0; w < WARMUPS; w++)); do |
| 61 | for e in "${engines[@]}"; do |
| 62 | IFS='|' read -r name jobs cmd <<< "$e" |
| 63 | # shellcheck disable=SC2086 |
| 64 | systemd-run --user --scope --quiet -p MemoryMax=3G --slice=claude-rc.slice -- \ |
| 65 | bash -c "$cmd" > /dev/null 2>&1 |
| 66 | done |
| 67 | done |
| 68 | |
| 69 | # Measured runs, interleaved ABC-ABC-... across engines. |
| 70 | for ((r = 0; r < RUNS; r++)); do |
| 71 | for e in "${engines[@]}"; do |
| 72 | IFS='|' read -r name jobs cmd <<< "$e" |
| 73 | run_timed "$docname" "$name" "$jobs" "$JSONL" -- bash -c "$cmd" |
| 74 | done |
| 75 | done |
| 76 | echo "[speed_bench] $docname: $((WARMUPS)) warm-up(s), $RUNS measured run(s) x ${#engines[@]} engines" >&2 |
| 77 | done |
| 78 | |
| 79 | echo "$JSONL" |