Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions crates/runner-shared/src/walltime_results/interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<f64>>,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open question: Would it make sense to have a struct here for those values to prevent issues where they are inserted in the wrong order? Or if one value too much/little is pushed? Or just for easier understanding?

Or maybe use a [f64; 100]? Wdyt?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess [f64; 100] is a good call. For the struct, I'm not sure, since we'd have to sort anyway when building. If the max is too big for f64, then we'll definitely not be able to store it in the DB, and also it's quite unlikely, since it would mean an iteration of over 100 days 🤣


pub rounds: u64,
/// Total time in **seconds**
Expand Down
21 changes: 21 additions & 0 deletions crates/runner-shared/src/walltime_results/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
Loading