//! Active-workload performance evidence (TRAFFIC-15). //! //! Deterministic ACTIVE workload — steering, braking, traffic, rule //! transitions, score updates — over the worst validated scenario, plus //! structural budget asserts (entity/event caps) that hold in ANY profile. //! Wall-clock numbers are REPORTED, never asserted: debug, idle, CPU-only, //! or no-GPU timings are diagnostic, never a release pass. Release budgets //! (§6) pass only from `cargo ... --release` runs on declared hardware //! with actual rendering/GPU; see `docs/PERF_BASELINE.md`. //! //! ```sh //! cargo test --locked -p nigig-traffic --test perf_release -- --test-threads=1 --nocapture //! ``` use nigig_traffic::traffic::{TrafficWorld, TICK_DT}; use std::time::Instant; fn percentile(mut v: Vec, p: f64) -> u128 { v.sort_unstable(); v[((p * v.len() as f64) as usize).min(v.len().saturating_sub(1))] } #[test] fn active_workload_reports_and_structural_budgets_hold() { // Worst validated scenario: most entities + a moving hazard. let scenarios = TrafficWorld::all_scenarios(); let mut worst = 0usize; let mut worst_ents = 0usize; for (i, _) in scenarios.iter().enumerate() { let mut w = TrafficWorld::new(); w.load_scenario(i); let n = w.sim.world.entities.len(); if n > worst_ents { worst_ents = n; worst = i; } } println!( "worst-content scenario: {} ({worst_ents} entities)", scenarios[worst].id ); // Structural budgets (§6) hold in every profile. assert!(worst_ents <= 256, "entity budget: {worst_ents}"); const { assert!(TICK_DT > 0.0) }; // Active workload: 60 s of scripted driving with steering reversals, // braking zones, and full-lock turns (rule transitions + score path). let mut w = TrafficWorld::new(); w.load_scenario(worst); // Skip intro for a pure Active measurement. for _ in 0..60 { w.tick(&makepad_game_blocks::DriveInput::default()); } let mut samples = Vec::with_capacity(3600); let mut inputs = 0u64; for i in 0..3600u64 { let phase = (i / 600) % 4; let input = makepad_game_blocks::DriveInput { steer: match phase { 0 => 0.6, 1 => -0.6, 2 => 1.0, _ => -1.0, }, throttle: if i % 900 < 700 { 0.8 } else { 0.0 }, brake: if i % 900 >= 700 { 0.8 } else { 0.0 }, ..makepad_game_blocks::DriveInput::default() }; let t0 = Instant::now(); w.tick(&input); samples.push(t0.elapsed().as_nanos()); inputs += 1; } assert_eq!(inputs, 3600); // The sim really ran: ticks advanced and the verdict histogram is live. assert_eq!(w.run.tick, 3660); let counts = w.verdict_counts(); assert!(counts.iter().sum::() > 0); let p50 = percentile(samples.clone(), 0.50); let p95 = percentile(samples.clone(), 0.95); let p99 = percentile(samples, 0.99); println!( "active tick ns p50={p50} p95={p95} p99={p99} (n=3600, profile-dependent, diagnostic only)" ); println!("verdict histogram: {counts:?}"); println!( "score: {}/{}", w.run.score.total_points, w.run.score.max_points ); }