Files
hakmem/scripts/run_benches.sh

80 lines
2.4 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
set -euo pipefail
# Simple all-in-one bench runner for HAKMEM vs System vs mimalloc
# - Focus: Mid/Large MT (832KiB) across multiple thread counts
# - Also runs Mixed (161024B) single-thread as a sanity check
#
# Optional: build or point to mimalloc shared library
# - If lib not found, mimalloc runs are skipped.
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)"
cd "$ROOT_DIR"
MIMALLOC_SO="${MIMALLOC_SO:-}"
if [[ -z "${MIMALLOC_SO}" ]]; then
# Try common local build path
if [[ -f /tmp/mimalloc-build/libmimalloc.so ]]; then
MIMALLOC_SO=/tmp/mimalloc-build/libmimalloc.so
elif [[ -L /tmp/mimalloc-build/libmimalloc.so ]]; then
MIMALLOC_SO=/tmp/mimalloc-build/libmimalloc.so
fi
fi
have_mimalloc=0
if [[ -n "${MIMALLOC_SO}" && -f "${MIMALLOC_SO}" ]]; then
have_mimalloc=1
fi
echo "== HAKMEM Bench Runner =="
echo "Repo: $ROOT_DIR"
echo "mimalloc: $([[ $have_mimalloc -eq 1 ]] && echo "found at ${MIMALLOC_SO}" || echo "not found (skipping)")"
echo
# Sanity: mixed (single-thread)
echo "-- Mixed (161024B, single-thread) --"
if [[ -x ./bench_random_mixed_system ]]; then
./bench_random_mixed_system | sed -n '1,8p' | sed 's/^/System | /'
else
echo "System | bench_random_mixed_system not found"
fi
if [[ -x ./bench_random_mixed_hakmem ]]; then
./bench_random_mixed_hakmem | sed -n '1,12p' | sed 's/^/HAKMEM | /'
else
echo "HAKMEM | bench_random_mixed_hakmem not found"
fi
echo
# Mid/Large MT across thread counts
echo "-- Mid/Large MT (832KiB), threads: 1,2,4,8 --"
THREADS_SET=(1 2 4 8)
CYCLES=40000
WS=128
SEED=42
for T in "${THREADS_SET[@]}"; do
echo "[threads=${T}]"
if [[ -x ./bench_mid_large_mt_system ]]; then
./bench_mid_large_mt_system "$T" "$CYCLES" "$WS" "$SEED" | sed -n '1,6p' | sed 's/^/System | /'
else
echo "System | bench_mid_large_mt_system not found"
fi
if [[ $have_mimalloc -eq 1 ]]; then
LD_LIBRARY_PATH="$(dirname "$MIMALLOC_SO"):${LD_LIBRARY_PATH:-}" \
LD_PRELOAD="$MIMALLOC_SO" \
./bench_mid_large_mt_system "$T" "$CYCLES" "$WS" "$SEED" | sed -n '1,6p' | sed 's/^/mimalloc | /'
else
echo "mimalloc | (skipped)"
fi
if [[ -x ./bench_mid_large_mt_hakmem ]]; then
./bench_mid_large_mt_hakmem "$T" "$CYCLES" "$WS" "$SEED" | sed -n '1,12p' | sed 's/^/HAKMEM | /'
else
echo "HAKMEM | bench_mid_large_mt_hakmem not found"
fi
echo
done
echo "== Done =="