//! Benchmark: 10k repeated (P,T) queries — cached vs uncached (Story 2.4 AC#4).
//!
//! Compares throughput of CachedBackend vs raw backend for repeated same-state queries.
//! Cached path should show significant speedup when the backend is expensive (e.g. CoolProp).

use criterion::{black_box, criterion_group, criterion_main, Criterion};
use entropyk_core::{Pressure, Temperature};
use entropyk_fluids::{CachedBackend, FluidBackend, FluidId, FluidState, Property, TestBackend};

const N_QUERIES: u32 = 10_000;

fn bench_uncached_10k(c: &mut Criterion) {
    let backend = TestBackend::new();
    let state = FluidState::from_pt(Pressure::from_bar(1.0), Temperature::from_celsius(25.0));
    let fluid = FluidId::new("R134a");

    c.bench_function("uncached_10k_same_state", |b| {
        b.iter(|| {
            for _ in 0..N_QUERIES {
                black_box(
                    backend
                        .property(fluid.clone(), Property::Density, state.clone())
                        .unwrap(),
                );
            }
        });
    });
}

fn bench_cached_10k(c: &mut Criterion) {
    let inner = TestBackend::new();
    let cached = CachedBackend::new(inner);
    let state = FluidState::from_pt(Pressure::from_bar(1.0), Temperature::from_celsius(25.0));
    let fluid = FluidId::new("R134a");

    c.bench_function("cached_10k_same_state", |b| {
        b.iter(|| {
            for _ in 0..N_QUERIES {
                black_box(
                    cached
                        .property(fluid.clone(), Property::Density, state.clone())
                        .unwrap(),
                );
            }
        });
    });
}

criterion_group!(benches, bench_uncached_10k, bench_cached_10k);
criterion_main!(benches);
