diff --git a/crates/runner-shared/src/walltime_results/interfaces.rs b/crates/runner-shared/src/walltime_results/interfaces.rs index f1330586a..a1a146504 100644 --- a/crates/runner-shared/src/walltime_results/interfaces.rs +++ b/crates/runner-shared/src/walltime_results/interfaces.rs @@ -18,6 +18,9 @@ pub struct BenchmarkStats { pub q1_ns: f64, pub median_ns: f64, pub q3_ns: f64, + /// p1..p99 of the time per iteration: `[24]`, `[49]` and `[74]` equal `q1_ns`, `median_ns` and `q3_ns` + #[serde(default, skip_serializing_if = "Option::is_none")] + pub percentiles_ns: Option>, pub rounds: u64, /// Total time in **seconds** diff --git a/crates/runner-shared/src/walltime_results/stats.rs b/crates/runner-shared/src/walltime_results/stats.rs index 39c72d0b8..fff555fd1 100644 --- a/crates/runner-shared/src/walltime_results/stats.rs +++ b/crates/runner-shared/src/walltime_results/stats.rs @@ -91,6 +91,7 @@ impl WalltimeBenchmark { q1_ns, median_ns, q3_ns, + percentiles_ns: None, rounds: rounds as u64, total_time: total_time_s, iqr_outlier_rounds, @@ -196,6 +197,26 @@ mod tests { ); } + #[test] + fn test_percentiles_are_optional_in_results_files() { + let benchmark = WalltimeBenchmark::from_runtime_data( + NAME.to_string(), + URI.to_string(), + vec![1], + vec![42], + None, + ); + let mut json = serde_json::to_value(&benchmark).unwrap(); + assert!(json["stats"].get("percentiles_ns").is_none()); + + let parsed: WalltimeBenchmark = serde_json::from_value(json.clone()).unwrap(); + assert_eq!(parsed.stats.percentiles_ns, None); + + json["stats"]["percentiles_ns"] = serde_json::json!([41.0, 42.0, 43.0]); + let parsed: WalltimeBenchmark = serde_json::from_value(json).unwrap(); + assert_eq!(parsed.stats.percentiles_ns, Some(vec![41.0, 42.0, 43.0])); + } + #[test] fn test_basic_stats_computation() { // Test with a simple benchmark with consistent iterations