CI / test (push) Failing after 11m6s
scripts/bench-build.sh copies the sources to a temp dir with its own target dir, so it never touches _build/ or files being edited. just bench [runs] ["tcc cc cc-release"]. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
73 lines
3.3 KiB
Bash
Executable File
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
|
|
# (run `just tcc-build` first; its own one-time build is not part of these numbers).
|
|
#
|
|
# 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; }
|
|
[ -x "$ROOT/_build/tcc/bin/tcc" ] || [ "$configs" = "cc" ] || { echo "error: run 'just tcc-build' first" >&2; exit 1; }
|
|
|
|
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
|