//! Backtesting proxy latency benchmark
//!
//! Measures routing overhead to confirm <10μs target

#[cfg(test)]
mod benchmarks {
    use super::super::BacktestingServiceProxy;
    use std::time::Instant;
    
    #[tokio::test]
    #[ignore = "Only run when backend is available"]
    async fn benchmark_routing_latency() {
        // This test requires a running backtesting service at localhost:50052
        let proxy = BacktestingServiceProxy::new("http://localhost:50052", None, None, None)
            .await
            .expect("Failed to create proxy");
        
        // Warmup
        for _ in 0..100 {
            let _health = proxy.health_checker.is_healthy().await;
        }
        
        // Measure
        let iterations = 10000;
        let start = Instant::now();
        
        for _ in 0..iterations {
            let _health = proxy.health_checker.is_healthy().await;
        }
        
        let elapsed = start.elapsed();
        let avg_us = elapsed.as_micros() as f64 / iterations as f64;
        
        println!("Average routing overhead: {:.2}μs", avg_us);
        println!("Target: <10μs");
        
        // This is just health checking, actual routing will be slightly higher
        // but should still be well under 10μs
        assert!(avg_us < 1.0, "Health check overhead too high: {:.2}μs", avg_us);
    }
}
