#!/bin/bash # Hybrid Performance Benchmark Runner for Rhailib # This script sets up the environment and runs the benchmarks set -e echo "๐Ÿš€ Rhailib Hybrid Performance Benchmark Runner" echo "==============================================" # Check if Redis is running echo "๐Ÿ“ก Checking Redis connection..." if ! redis-cli ping > /dev/null 2>&1; then echo "โŒ Redis is not running. Please start Redis server:" echo " redis-server" exit 1 fi echo "โœ… Redis is running" # Check if we're in the right directory if [ ! -f "Cargo.toml" ] || [ ! -d "scripts" ]; then echo "โŒ Please run this script from the rhailib root directory" exit 1 fi # Build the worker binary in release mode for performance echo "๐Ÿ”จ Building worker binary in release mode..." cd src/worker cargo build --release --bin worker cd ../.. echo "โœ… Worker binary built (release mode)" # Clear any existing Redis data echo "๐Ÿงน Clearing Redis test data..." redis-cli FLUSHDB > /dev/null echo "โœ… Redis data cleared" # Parse command line arguments BENCHMARK_TYPE="full" TASK_COUNT="" WORKER_COUNT="" while [[ $# -gt 0 ]]; do case $1 in --demo) BENCHMARK_TYPE="demo" shift ;; --quick) BENCHMARK_TYPE="quick" shift ;; --tasks) TASK_COUNT="$2" shift 2 ;; --workers) WORKER_COUNT="$2" shift 2 ;; --help|-h) echo "Usage: $0 [OPTIONS]" echo "" echo "Options:" echo " --demo Run demo script instead of full benchmarks" echo " --quick Run quick benchmarks (fewer configurations)" echo " --tasks N Override task count for demo" echo " --workers N Override worker count for demo" echo " --help, -h Show this help message" echo "" echo "Examples:" echo " $0 # Run full benchmarks" echo " $0 --demo # Run demo script" echo " $0 --quick # Run quick benchmarks" echo " $0 --demo --tasks 50 --workers 4 # Custom demo" exit 0 ;; *) echo "โŒ Unknown option: $1" echo "Use --help for usage information" exit 1 ;; esac done case $BENCHMARK_TYPE in "demo") echo "๐ŸŽฏ Running benchmark demo..." if [ -n "$TASK_COUNT" ] || [ -n "$WORKER_COUNT" ]; then echo "โš ๏ธ Custom task/worker counts not yet supported in demo" echo " Using default values (100 tasks, 2 workers)" fi cargo run --example run_benchmark_demo ;; "quick") echo "โšก Running quick benchmarks..." echo " This will test basic configurations only" cargo bench --bench rhai_performance_bench -- --quick ;; "full") echo "๐Ÿ Running full benchmark suite..." echo " This may take several minutes..." cargo bench --bench rhai_performance_bench echo "" echo "๐Ÿ“Š Benchmark results saved to: target/criterion/" echo " Open target/criterion/report/index.html to view detailed results" ;; esac echo "" echo "๐ŸŽ‰ Benchmark run completed!" echo "" echo "๐Ÿ“ˆ Next steps:" echo " โ€ข View HTML reports in target/criterion/report/" echo " โ€ข Run 'cargo bench' for full Criterion benchmarks" echo " โ€ข Run '$0 --demo' for a quick demonstration" echo " โ€ข Check BENCHMARK_README.md for detailed documentation"