#!/bin/bash
# Quick Performance Check Script
# Tests key endpoints and reports response times

echo "============================================================"
echo "QUICK PERFORMANCE CHECK"
echo "============================================================"
echo ""

BASE_URL="${1:-http://localhost:10000}"
echo "Testing: $BASE_URL"
echo ""

# Test endpoints
ENDPOINTS=(
  "/"
  "/contact"
  "/about"
  "/api/health.json"
)

echo "Endpoint Performance:"
echo "------------------------------------------------------------"

for endpoint in "${ENDPOINTS[@]}"; do
    url="${BASE_URL}${endpoint}"

    # Run curl and capture timing
    time_total=$(curl -w "%{time_total}" -o /dev/null -s "$url")
    http_code=$(curl -w "%{http_code}" -o /dev/null -s "$url")

    # Convert to milliseconds
    time_ms=$(echo "$time_total * 1000" | bc)

    # Determine status
    if (( $(echo "$time_total < 0.2" | bc -l) )); then
        status="EXCELLENT"
    elif (( $(echo "$time_total < 0.5" | bc -l) )); then
        status="GOOD"
    else
        status="SLOW"
    fi

    printf "%-30s %6.2fms  [%s] (HTTP %s)\n" "$endpoint" "$time_ms" "$status" "$http_code"
done

echo ""
echo "============================================================"
echo "Performance Target: < 500ms"
echo "Optimal: < 200ms"
echo "============================================================"
