#!/usr/bin/env bash set -euo pipefail # Run tiny hot bench across sizes/batches for HAKMEM, System, mimalloc (direct-link triad) # Usage: scripts/run_tiny_hot_triad.sh [cycles] ROOT_DIR=$(cd "$(dirname "$0")/.." && pwd) cd "$ROOT_DIR" cycles=${1:-100000} if [[ "${SKIP_BUILD:-0}" != "1" ]]; then echo "[build] benches (fast + mi)" make -s bench_fast bench_tiny_hot_mi >/dev/null else echo "[build] skipped (SKIP_BUILD=1)" fi # Ensure LD_LIBRARY_PATH is defined (set -u safety) export LD_LIBRARY_PATH="${LD_LIBRARY_PATH:-}" MI_LIBDIR="$ROOT_DIR/mimalloc-bench/extern/mi/out/release" TS=$(date +%Y%m%d_%H%M%S) OUTDIR="bench_results/tiny_hot_triad_${TS}" mkdir -p "$OUTDIR" CSV="$OUTDIR/results.csv" echo "size,batch,cycles,allocator,throughput_mops" > "$CSV" sizes=(8 16 24 32 40 48 56 64 128) batches=(50 100 200) run_case() { local size="$1"; shift local batch="$1"; shift local cyc="$1"; shift local bin="$1"; shift local alloc="$1"; shift local out if [[ "$alloc" == "mimalloc" ]]; then LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$MI_LIBDIR" \ $bin "$size" "$batch" "$cyc" | sed -n 's/^Throughput: \([0-9.][0-9.]*\) M ops.*/\1/p' >"$OUTDIR/tmp.txt" || true else $bin "$size" "$batch" "$cyc" | sed -n 's/^Throughput: \([0-9.][0-9.]*\) M ops.*/\1/p' >"$OUTDIR/tmp.txt" || true fi out=$(cat "$OUTDIR/tmp.txt" || true) if [[ -n "$out" ]]; then echo "$size,$batch,$cyc,$alloc,$out" >> "$CSV"; fi } for s in "${sizes[@]}"; do for b in "${batches[@]}"; do echo "[run] HAKMEM size=$s batch=$b cycles=$cycles" run_case "$s" "$b" "$cycles" ./bench_tiny_hot_hakmem hakmem echo "[run] SYSTEM size=$s batch=$b cycles=$cycles" run_case "$s" "$b" "$cycles" ./bench_tiny_hot_system system echo "[run] MIMALLOC size=$s batch=$b cycles=$cycles" run_case "$s" "$b" "$cycles" ./bench_tiny_hot_mi mimalloc done done echo "[done] CSV: $CSV" sed -n '1,40p' "$CSV" || true