Files
chandra/scripts/bench-build.sh
nandiandClaude Sonnet 5.5 92d2b29889
CI / test (push) Failing after 35s
just build no longer builds tcc: use $TCC, an already-built vendored tcc, or tcc on PATH
scripts/tcc/tcc resolves the compiler (and errors with how to get one if none exists);
tcc-build stays as an optional recipe. bench no longer depends on it either.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-25 01:27:00 -08:00

73 lines
3.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Benchmark the native compositor build, for each compiler configuration:
# cold a fresh target dir (nothing cached)
# warm rebuild with nothing changed
# incr rebuild after touching one source file (compositor/shell/shell.mbt, then lib/ui/ui.mbt)
# Runs on a throwaway copy of the sources with its own target dir, so it never touches your
# _build/ or the files other people are editing. The tcc configs use the repo's vendored tinycc
# (any tcc scripts/tcc/tcc can find; see that script).
#
# scripts/bench-build.sh [runs=3] ["tcc cc cc-release"]
# tcc debug build, compiled and linked with the vendored tinycc (what `just build` does)
# cc debug build with the system C compiler
# cc-release --release build with the system C compiler (what `just build-release` does)
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
export PATH="$HOME/.moon/bin:$PATH"
runs="${1:-3}"
configs="${2:-tcc cc}"
command -v moon >/dev/null || { echo "error: moon not found" >&2; exit 1; }
case " $configs " in *" tcc "*) "$ROOT/scripts/tcc/tcc" --which >/dev/null || exit 1 ;; esac
work="$(mktemp -d)"
trap 'rm -rf "$work"' EXIT
mkdir -p "$work/src"
tar -C "$ROOT" --exclude=./_build --exclude=./build --exclude=./.git --exclude=./.tools --exclude=./.pixi -cf - . | tar -C "$work/src" -xf -
now() { date +%s.%N; }
median() { sort -n | awk '{a[NR]=$1} END {if (NR%2) print a[(NR+1)/2]; else print (a[NR/2]+a[NR/2+1])/2}'; }
# build <config> <target-dir> -> runs one build, output discarded; returns its exit status
build() {
local cfg="$1" tdir="$2"
(
cd "$work/src"
case "$cfg" in
tcc) export MOON_CC="$ROOT/scripts/tcc/tcc" MOON_STUB_CC="$ROOT/scripts/tcc/tcc"; flags=() ;;
cc) flags=() ;;
cc-release) flags=(--release) ;;
*) echo "unknown config $cfg" >&2; exit 2 ;;
esac
moon build --target native "${flags[@]}" --warn-list -a --target-dir "$tdir" compositor/bin >"$work/build.log" 2>&1
)
}
# timed <cmd...>: print the elapsed seconds; a failing build aborts the whole benchmark.
timed() {
local t0 t1
t0=$(now)
"$@" || { touch "$work/failed"; echo 0; return 0; }
t1=$(now)
awk -v a="$t0" -v b="$t1" 'BEGIN { printf "%.3f\n", b - a }'
}
touch_n=0
touch_src() { touch_n=$((touch_n + 1)); printf '\n///|\nfn bench_touch_%s() -> Unit {\n ()\n}\n' "$touch_n" >> "$work/src/$1"; }
printf '%-12s %10s %10s %14s %12s (median of %s, seconds)\n' config cold warm "incr:shell.mbt" "incr:ui.mbt" "$runs"
for cfg in $configs; do
cold=(); warm=(); incr_shell=(); incr_ui=()
for i in $(seq 1 "$runs"); do
tdir="$work/target-$cfg-$i"
cold+=("$(timed build "$cfg" "$tdir")")
warm+=("$(timed build "$cfg" "$tdir")")
touch_src compositor/shell/shell.mbt
incr_shell+=("$(timed build "$cfg" "$tdir")")
touch_src lib/ui/ui.mbt
incr_ui+=("$(timed build "$cfg" "$tdir")")
rm -rf "$tdir"
[ ! -e "$work/failed" ] || { echo "error: a '$cfg' build failed:" >&2; grep -v "^/home.*warning:" "$work/build.log" | tail -25 >&2; exit 1; }
done
printf '%-12s %10.2f %10.2f %14.2f %12.2f\n' "$cfg" \
"$(printf '%s\n' "${cold[@]}" | median)" "$(printf '%s\n' "${warm[@]}" | median)" \
"$(printf '%s\n' "${incr_shell[@]}" | median)" "$(printf '%s\n' "${incr_ui[@]}" | median)"
done