#!/usr/bin/env bash set -euo pipefail # Run random-mixed bench for HAKMEM, System, mimalloc across ws/seeds and write CSV # Usage: scripts/run_random_mixed_matrix.sh [cycles] ROOT_DIR=$(cd "$(dirname "$0")/.." && pwd) cd "$ROOT_DIR" cycles=${1:-150000} echo "[build] benches (fast + random-mixed variants)" make -s bench_fast bench_random_mixed_hakmem bench_random_mixed_system bench_random_mixed_mi >/dev/null # 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/random_mixed_${TS}" mkdir -p "$OUTDIR" CSV="$OUTDIR/results.csv" echo "allocator,cycles,ws,seed,throughput_mops" > "$CSV" ws_list=(200 400 800) seeds=(42 1337) run_case() { local bin="$1"; shift local alloc="$1"; shift local cyc="$1"; shift local ws="$1"; shift local seed="$1"; shift local out if [[ "$alloc" == "mimalloc" ]]; then LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$MI_LIBDIR" \ $bin "$cyc" "$ws" "$seed" | sed -n 's/^Throughput: \([0-9.][0-9.]*\) M ops.*/\1/p' >"$OUTDIR/tmp.txt" || true else $bin "$cyc" "$ws" "$seed" | 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 "$alloc,$cyc,$ws,$seed,$out" >> "$CSV"; fi } for ws in "${ws_list[@]}"; do for seed in "${seeds[@]}"; do echo "[run] HAKMEM ws=$ws seed=$seed cycles=$cycles" run_case ./bench_random_mixed_hakmem hakmem "$cycles" "$ws" "$seed" echo "[run] SYSTEM ws=$ws seed=$seed cycles=$cycles" run_case ./bench_random_mixed_system system "$cycles" "$ws" "$seed" echo "[run] MIMALLOC ws=$ws seed=$seed cycles=$cycles" run_case ./bench_random_mixed_mi mimalloc "$cycles" "$ws" "$seed" done done echo "[done] CSV: $CSV" sed -n '1,40p' "$CSV" || true