- Fix curl -w override bug: consolidate --write-out/"-w" into single
-w "%{http_code} %{time_total}" so STATUS and TIMING are both captured
- Add ?nocache=1 to render URL so baseline measures cold render time
- Fix duplicate BASELINE.md Section 2 rows (batting vs pitching)
- Add benchmarks/render_timings.txt to .gitignore
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
76 lines
2.9 KiB
Bash
Executable File
76 lines
2.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# WP-00: Baseline benchmark — sequential card render timing
|
|
#
|
|
# Measures per-card render time for 10 cards by calling the card image
|
|
# endpoint sequentially and recording curl's time_total for each request.
|
|
#
|
|
# Usage:
|
|
# API_BASE=http://pddev.manticorum.com:816 ./benchmarks/benchmark_renders.sh
|
|
# API_BASE=http://localhost:8000 CARD_TYPE=pitching ./benchmarks/benchmark_renders.sh
|
|
# API_BASE=http://pddev.manticorum.com:816 ./benchmarks/benchmark_renders.sh 101 102 103
|
|
#
|
|
# Arguments (optional): explicit player IDs to render. If omitted, the script
|
|
# queries the API for the first 10 players in the live cardset.
|
|
#
|
|
# Output: results are printed to stdout and appended to benchmarks/render_timings.txt
|
|
|
|
set -euo pipefail
|
|
|
|
API_BASE="${API_BASE:-http://localhost:8000}"
|
|
CARD_TYPE="${CARD_TYPE:-batting}"
|
|
OUTFILE="$(dirname "$0")/render_timings.txt"
|
|
|
|
echo "=== Card Render Benchmark ===" | tee -a "$OUTFILE"
|
|
echo "Date: $(date -u +%Y-%m-%dT%H:%M:%SZ)" | tee -a "$OUTFILE"
|
|
echo "API: $API_BASE" | tee -a "$OUTFILE"
|
|
echo "Type: $CARD_TYPE" | tee -a "$OUTFILE"
|
|
|
|
# --- Resolve player IDs ---
|
|
if [ "$#" -gt 0 ]; then
|
|
PLAYER_IDS=("$@")
|
|
echo "Mode: explicit IDs (${#PLAYER_IDS[@]} players)" | tee -a "$OUTFILE"
|
|
else
|
|
echo "Mode: auto-fetch first 10 players from live cardset" | tee -a "$OUTFILE"
|
|
# Fetch player list and extract IDs; requires jq
|
|
RAW=$(curl -sf "$API_BASE/api/v2/players?page_size=10")
|
|
PLAYER_IDS=($(echo "$RAW" | jq -r '.players[].id // .[]?.id // .[]' 2>/dev/null | head -10))
|
|
if [ "${#PLAYER_IDS[@]}" -eq 0 ]; then
|
|
echo "ERROR: Could not fetch player IDs from $API_BASE/api/v2/players" | tee -a "$OUTFILE"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
echo "Players: ${PLAYER_IDS[*]}" | tee -a "$OUTFILE"
|
|
echo "" | tee -a "$OUTFILE"
|
|
|
|
# --- Run renders ---
|
|
TOTAL=0
|
|
COUNT=0
|
|
|
|
for player_id in "${PLAYER_IDS[@]}"; do
|
|
# Bypass cached PNG files; remove ?nocache=1 after baseline is captured to test cache-hit performance.
|
|
URL="$API_BASE/api/v2/players/$player_id/${CARD_TYPE}card?nocache=1"
|
|
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code} %{time_total}" "$URL" 2>&1)
|
|
STATUS=$(echo "$HTTP_CODE" | awk '{print $1}')
|
|
TIMING=$(echo "$HTTP_CODE" | awk '{print $2}')
|
|
echo " player_id=$player_id http=$STATUS time=${TIMING}s" | tee -a "$OUTFILE"
|
|
if [ "$STATUS" = "200" ]; then
|
|
TOTAL=$(echo "$TOTAL + $TIMING" | bc -l)
|
|
COUNT=$((COUNT + 1))
|
|
fi
|
|
done
|
|
|
|
# --- Summary ---
|
|
echo "" | tee -a "$OUTFILE"
|
|
if [ "$COUNT" -gt 0 ]; then
|
|
AVG=$(echo "scale=3; $TOTAL / $COUNT" | bc -l)
|
|
echo "Successful renders: $COUNT / ${#PLAYER_IDS[@]}" | tee -a "$OUTFILE"
|
|
echo "Total time: ${TOTAL}s" | tee -a "$OUTFILE"
|
|
echo "Average: ${AVG}s per render" | tee -a "$OUTFILE"
|
|
else
|
|
echo "No successful renders — check API_BASE and player IDs" | tee -a "$OUTFILE"
|
|
fi
|
|
echo "---" | tee -a "$OUTFILE"
|
|
echo "" | tee -a "$OUTFILE"
|
|
echo "Results appended to $OUTFILE"
|