#!/bin/bash

# Image Processing Benchmark Runner (Linux/Mac)
# This script provides easy access to common benchmark scenarios

show_help() {
    cat << EOF
Image Processing Benchmark Runner
==================================

Usage: ./run-benchmarks.sh [scenario] [--fast] [--verbose]

Scenarios:
  all       - Run all benchmarks (60-120 minutes)
  quick     - Fast test run for development (5-10 minutes)
  parallel  - Test parallel processing strategies (20-30 minutes)
  chunks    - Optimize chunk size (20-30 minutes)
  sizes     - Test different image sizes (45-90 minutes)
  stress    - Large-scale stress test (2-4 hours)
  help      - Show this help message

Flags:
  --fast    - Use dry run for faster but less accurate results
  --verbose - Show detailed output

Examples:
  ./run-benchmarks.sh quick
  ./run-benchmarks.sh parallel --fast
  ./run-benchmarks.sh stress --verbose

Results will be saved to: MaddoShared.Benchmarks/BenchmarkDotNet.Artifacts/results/
EOF
}

run_benchmark() {
    local filter=$1
    local description=$2
    
    echo ""
    echo "========================================"
    echo " $description"
    echo "========================================"
    echo ""
    
    local args="-c Release"
    
    if [ -n "$filter" ]; then
        args="$args -- --filter \"$filter\""
    fi
    
    if [ "$fast_mode" = true ]; then
        args="$args --job dry"
    fi
    
    if [ "$verbose_mode" = true ]; then
        args="$args --verbose"
    fi
    
    cd MaddoShared.Benchmarks
    eval "dotnet run $args"
    cd ..
}

# Parse arguments
scenario="${1:-help}"
fast_mode=false
verbose_mode=false

shift
while [ $# -gt 0 ]; do
    case "$1" in
        --fast)
            fast_mode=true
            ;;
        --verbose)
            verbose_mode=true
            ;;
    esac
    shift
done

# Main execution
case "$scenario" in
    help)
        show_help
        ;;
    
    all)
        echo "Running ALL benchmarks..."
        echo "This will take 60-120 minutes. Press Ctrl+C to cancel."
        echo ""
        sleep 3
        run_benchmark "" "All Benchmarks"
        ;;
    
    quick)
        echo "Running QUICK test..."
        run_benchmark "*ImageProcessingBenchmarks*" "Quick Development Test"
        ;;
    
    parallel)
        echo "Running PARALLEL processing benchmarks..."
        run_benchmark "*ImageProcessingBenchmarks*" "Parallel Processing Strategies"
        ;;
    
    chunks)
        echo "Running CHUNK SIZE optimization..."
        run_benchmark "*ChunkSizeBenchmarks*" "Chunk Size Optimization"
        ;;
    
    sizes)
        echo "Running IMAGE SIZE comparison..."
        run_benchmark "*ImageSizeBenchmarks*" "Image Size Impact Analysis"
        ;;
    
    stress)
        echo "Running STRESS TEST..."
        echo "WARNING: This will take 2-4 hours and use significant disk space!"
        echo "Press Ctrl+C within 5 seconds to cancel..."
        echo ""
        sleep 5
        run_benchmark "*StressTestBenchmark*" "Large-Scale Stress Test"
        ;;
    
    *)
        echo "Unknown scenario: $scenario"
        echo "Run './run-benchmarks.sh help' for usage information"
        exit 1
        ;;
esac

echo ""
echo "Benchmark execution complete!"
echo "Results saved to: MaddoShared.Benchmarks/BenchmarkDotNet.Artifacts/results/"
