Files
hakmem/run_phase8_comprehensive_benchmark.sh

130 lines
5.4 KiB
Bash
Raw Normal View History

#!/bin/bash
# Phase 8 Comprehensive Allocator Comparison
# Compares HAKMEM (Phase 8) vs System malloc vs mimalloc
set -e
WORKDIR="/mnt/workdisk/public_share/hakmem"
cd "$WORKDIR"
OUTPUT_FILE="phase8_comprehensive_benchmark_results.txt"
rm -f "$OUTPUT_FILE"
echo "=====================================================================" | tee -a "$OUTPUT_FILE"
echo "Phase 8 Comprehensive Allocator Comparison" | tee -a "$OUTPUT_FILE"
echo "Date: $(date)" | tee -a "$OUTPUT_FILE"
echo "=====================================================================" | tee -a "$OUTPUT_FILE"
echo "" | tee -a "$OUTPUT_FILE"
# Verify binaries exist
echo "Verifying binaries..." | tee -a "$OUTPUT_FILE"
for binary in bench_random_mixed_hakmem bench_random_mixed_system bench_random_mixed_mi; do
if [ ! -x "$binary" ]; then
echo "ERROR: $binary not found or not executable" | tee -a "$OUTPUT_FILE"
exit 1
fi
echo "$binary" | tee -a "$OUTPUT_FILE"
done
echo "" | tee -a "$OUTPUT_FILE"
# Benchmark configurations
ITERATIONS=10000000
WORKING_SETS=(256 8192)
NUM_RUNS=5
# Function to run benchmark
run_benchmark() {
local binary=$1
local allocator=$2
local working_set=$3
local run_num=$4
echo "[$allocator] Working Set $working_set - Run $run_num/5..." | tee -a "$OUTPUT_FILE"
# Run and capture output
result=$(./$binary $ITERATIONS $working_set 2>&1)
echo "$result" >> "$OUTPUT_FILE"
# Extract M ops/s
ops=$(echo "$result" | grep -oP '\d+\.\d+(?= M ops/s)' | head -1)
echo "$ops"
}
# Arrays to store results
declare -A results_hakmem_256
declare -A results_system_256
declare -A results_mi_256
declare -A results_hakmem_8192
declare -A results_system_8192
declare -A results_mi_8192
echo "=====================================================================" | tee -a "$OUTPUT_FILE"
echo "BENCHMARK 1: Working Set 256 (Hot cache, Phase 7 comparison)" | tee -a "$OUTPUT_FILE"
echo "=====================================================================" | tee -a "$OUTPUT_FILE"
echo "" | tee -a "$OUTPUT_FILE"
# Working Set 256
echo "--- HAKMEM (Phase 8) - Working Set 256 ---" | tee -a "$OUTPUT_FILE"
for i in {1..5}; do
results_hakmem_256[$i]=$(run_benchmark "bench_random_mixed_hakmem" "HAKMEM" 256 $i)
done
echo "" | tee -a "$OUTPUT_FILE"
echo "--- System malloc (glibc) - Working Set 256 ---" | tee -a "$OUTPUT_FILE"
for i in {1..5}; do
results_system_256[$i]=$(run_benchmark "bench_random_mixed_system" "System" 256 $i)
done
echo "" | tee -a "$OUTPUT_FILE"
echo "--- mimalloc - Working Set 256 ---" | tee -a "$OUTPUT_FILE"
for i in {1..5}; do
results_mi_256[$i]=$(run_benchmark "bench_random_mixed_mi" "mimalloc" 256 $i)
done
echo "" | tee -a "$OUTPUT_FILE"
echo "=====================================================================" | tee -a "$OUTPUT_FILE"
echo "BENCHMARK 2: Working Set 8192 (Realistic workload)" | tee -a "$OUTPUT_FILE"
echo "=====================================================================" | tee -a "$OUTPUT_FILE"
echo "" | tee -a "$OUTPUT_FILE"
# Working Set 8192
echo "--- HAKMEM (Phase 8) - Working Set 8192 ---" | tee -a "$OUTPUT_FILE"
for i in {1..5}; do
results_hakmem_8192[$i]=$(run_benchmark "bench_random_mixed_hakmem" "HAKMEM" 8192 $i)
done
echo "" | tee -a "$OUTPUT_FILE"
echo "--- System malloc (glibc) - Working Set 8192 ---" | tee -a "$OUTPUT_FILE"
for i in {1..5}; do
results_system_8192[$i]=$(run_benchmark "bench_random_mixed_system" "System" 8192 $i)
done
echo "" | tee -a "$OUTPUT_FILE"
echo "--- mimalloc - Working Set 8192 ---" | tee -a "$OUTPUT_FILE"
for i in {1..5}; do
results_mi_8192[$i]=$(run_benchmark "bench_random_mixed_mi" "mimalloc" 8192 $i)
done
echo "" | tee -a "$OUTPUT_FILE"
echo "=====================================================================" | tee -a "$OUTPUT_FILE"
echo "RAW DATA SUMMARY" | tee -a "$OUTPUT_FILE"
echo "=====================================================================" | tee -a "$OUTPUT_FILE"
echo "" | tee -a "$OUTPUT_FILE"
echo "Working Set 256:" | tee -a "$OUTPUT_FILE"
echo " HAKMEM: ${results_hakmem_256[1]}, ${results_hakmem_256[2]}, ${results_hakmem_256[3]}, ${results_hakmem_256[4]}, ${results_hakmem_256[5]}" | tee -a "$OUTPUT_FILE"
echo " System: ${results_system_256[1]}, ${results_system_256[2]}, ${results_system_256[3]}, ${results_system_256[4]}, ${results_system_256[5]}" | tee -a "$OUTPUT_FILE"
echo " mimalloc: ${results_mi_256[1]}, ${results_mi_256[2]}, ${results_mi_256[3]}, ${results_mi_256[4]}, ${results_mi_256[5]}" | tee -a "$OUTPUT_FILE"
echo "" | tee -a "$OUTPUT_FILE"
echo "Working Set 8192:" | tee -a "$OUTPUT_FILE"
echo " HAKMEM: ${results_hakmem_8192[1]}, ${results_hakmem_8192[2]}, ${results_hakmem_8192[3]}, ${results_hakmem_8192[4]}, ${results_hakmem_8192[5]}" | tee -a "$OUTPUT_FILE"
echo " System: ${results_system_8192[1]}, ${results_system_8192[2]}, ${results_system_8192[3]}, ${results_system_8192[4]}, ${results_system_8192[5]}" | tee -a "$OUTPUT_FILE"
echo " mimalloc: ${results_mi_8192[1]}, ${results_mi_8192[2]}, ${results_mi_8192[3]}, ${results_mi_8192[4]}, ${results_mi_8192[5]}" | tee -a "$OUTPUT_FILE"
echo "" | tee -a "$OUTPUT_FILE"
echo "=====================================================================" | tee -a "$OUTPUT_FILE"
echo "Benchmark completed! Results saved to: $OUTPUT_FILE" | tee -a "$OUTPUT_FILE"
echo "=====================================================================" | tee -a "$OUTPUT_FILE"