//! Times the Rust side of one `compute_status` IPC round trip against a real
//! payload file: arg deserialization -> engine -> response serialization.
//! Usage: cargo run --release -p cambium-core --example status_bench <inputs.json>

use std::time::Instant;

fn main() {
    let path = std::env::args().nth(1).expect("usage: status_bench <inputs.json>");
    let raw = std::fs::read_to_string(&path).expect("read inputs");
    println!("payload: {} ({:.2} MB)", path, raw.len() as f64 / 1e6);

    for run in 0..5 {
        let t0 = Instant::now();
        let inputs: cambium_core::gui::StatusInputsDto =
            serde_json::from_str(&raw).expect("deserialize");
        let t1 = Instant::now();
        let resp = cambium_core::gui::compute_status_dto(inputs);
        let t2 = Instant::now();
        let out = serde_json::to_string(&resp).expect("serialize");
        let t3 = Instant::now();
        println!(
            "run {run}: deserialize={:>7.2?}  engine={:>7.2?}  serialize={:>7.2?}  total={:>7.2?}  resp={:.2} MB  statuses={}",
            t1 - t0,
            t2 - t1,
            t3 - t2,
            t3 - t0,
            out.len() as f64 / 1e6,
            resp.statuses.len()
        );
    }
}
