Skip to content

Commit 5c0b0a3

Browse files
authored
Merge pull request #1398 from rylev/add-metric-to-table
Add the metric in question to markdown table
2 parents fe75032 + b24b75e commit 5c0b0a3

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

site/src/comparison.rs

+19-21
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub async fn handle_triage(
9696
.clone()
9797
.summarize_by_category(&benchmark_map);
9898
let mut result = String::from("**Summary**:\n\n");
99-
write_summary_table(&primary, &secondary, false, &mut result);
99+
write_summary_table(&primary, &secondary, false, true, &mut result);
100100
result
101101
}
102102
None => String::from("**ERROR**: no data found for end bound"),
@@ -513,7 +513,7 @@ async fn write_triage_summary(
513513
let link = &compare_link(start, end);
514514
write!(&mut result, " [(Comparison Link)]({})\n\n", link).unwrap();
515515

516-
write_summary_table(&primary, &secondary, false, &mut result);
516+
write_summary_table(&primary, &secondary, false, true, &mut result);
517517

518518
result
519519
}
@@ -523,8 +523,21 @@ pub fn write_summary_table(
523523
primary: &ArtifactComparisonSummary,
524524
secondary: &ArtifactComparisonSummary,
525525
with_footnotes: bool,
526+
include_metric: bool,
526527
result: &mut String,
527528
) {
529+
let metric = include_metric
530+
.then(|| {
531+
primary
532+
.relevant_comparisons
533+
.first()
534+
.or(secondary.relevant_comparisons.first())
535+
.map(|m| m.metric.as_str())
536+
})
537+
.flatten()
538+
// we want at least 10 spaces to accommodate "count[^2]"
539+
.unwrap_or(" ");
540+
528541
fn render_stat<F: FnOnce() -> Option<f64>>(count: usize, calculate: F) -> String {
529542
let value = if count > 0 { calculate() } else { None };
530543
value
@@ -627,7 +640,7 @@ pub fn write_summary_table(
627640
// This code attempts to space the table cells evenly so that the data is
628641
// easy to read for anyone who is viewing the Markdown source.
629642
let column_labels = [
630-
" ".to_string(), // we want at least 10 spaces to accommodate "count[^2]"
643+
format!("({metric})"),
631644
format!("mean{}", if with_footnotes { "[^1]" } else { "" }),
632645
"max".to_string(),
633646
format!("count{}", if with_footnotes { "[^2]" } else { "" }),
@@ -1383,8 +1396,6 @@ mod tests {
13831396
(Category::Primary, 1.0, 3.0),
13841397
],
13851398
r#"
1386-
| | mean[^1] | max | count[^2] |
1387-
|:----------:|:--------:|:---:|:---------:|
13881399
| Regressions ❌ <br /> (primary) | 146.7% | 200.0% | 3 |
13891400
| Regressions ❌ <br /> (secondary) | - | - | 0 |
13901401
| Improvements ✅ <br /> (primary) | - | - | 0 |
@@ -1404,8 +1415,6 @@ mod tests {
14041415
(Category::Primary, 4.0, 1.0),
14051416
],
14061417
r#"
1407-
| | mean[^1] | max | count[^2] |
1408-
|:----------:|:--------:|:---:|:---------:|
14091418
| Regressions ❌ <br /> (primary) | - | - | 0 |
14101419
| Regressions ❌ <br /> (secondary) | - | - | 0 |
14111420
| Improvements ✅ <br /> (primary) | -71.7% | -80.0% | 3 |
@@ -1425,8 +1434,6 @@ mod tests {
14251434
(Category::Secondary, 4.0, 1.0),
14261435
],
14271436
r#"
1428-
| | mean[^1] | max | count[^2] |
1429-
|:----------:|:--------:|:---:|:---------:|
14301437
| Regressions ❌ <br /> (primary) | - | - | 0 |
14311438
| Regressions ❌ <br /> (secondary) | - | - | 0 |
14321439
| Improvements ✅ <br /> (primary) | - | - | 0 |
@@ -1446,8 +1453,6 @@ mod tests {
14461453
(Category::Secondary, 1.0, 3.0),
14471454
],
14481455
r#"
1449-
| | mean[^1] | max | count[^2] |
1450-
|:----------:|:--------:|:---:|:---------:|
14511456
| Regressions ❌ <br /> (primary) | - | - | 0 |
14521457
| Regressions ❌ <br /> (secondary) | 146.7% | 200.0% | 3 |
14531458
| Improvements ✅ <br /> (primary) | - | - | 0 |
@@ -1468,8 +1473,6 @@ mod tests {
14681473
(Category::Primary, 4.0, 1.0),
14691474
],
14701475
r#"
1471-
| | mean[^1] | max | count[^2] |
1472-
|:----------:|:--------:|:---:|:---------:|
14731476
| Regressions ❌ <br /> (primary) | 150.0% | 200.0% | 2 |
14741477
| Regressions ❌ <br /> (secondary) | - | - | 0 |
14751478
| Improvements ✅ <br /> (primary) | -62.5% | -75.0% | 2 |
@@ -1492,8 +1495,6 @@ mod tests {
14921495
(Category::Primary, 4.0, 1.0),
14931496
],
14941497
r#"
1495-
| | mean[^1] | max | count[^2] |
1496-
|:----------:|:--------:|:---:|:---------:|
14971498
| Regressions ❌ <br /> (primary) | 150.0% | 200.0% | 2 |
14981499
| Regressions ❌ <br /> (secondary) | 100.0% | 100.0% | 1 |
14991500
| Improvements ✅ <br /> (primary) | -62.5% | -75.0% | 2 |
@@ -1512,8 +1513,6 @@ mod tests {
15121513
(Category::Primary, 5.0, 6.0),
15131514
],
15141515
r#"
1515-
| | mean[^1] | max | count[^2] |
1516-
|:----------:|:--------:|:---:|:---------:|
15171516
| Regressions ❌ <br /> (primary) | 20.0% | 20.0% | 1 |
15181517
| Regressions ❌ <br /> (secondary) | - | - | 0 |
15191518
| Improvements ✅ <br /> (primary) | -50.0% | -50.0% | 1 |
@@ -1532,8 +1531,6 @@ mod tests {
15321531
(Category::Primary, 6.0, 5.0),
15331532
],
15341533
r#"
1535-
| | mean[^1] | max | count[^2] |
1536-
|:----------:|:--------:|:---:|:---------:|
15371534
| Regressions ❌ <br /> (primary) | 100.0% | 100.0% | 1 |
15381535
| Regressions ❌ <br /> (secondary) | - | - | 0 |
15391536
| Improvements ✅ <br /> (primary) | -16.7% | -16.7% | 1 |
@@ -1587,7 +1584,8 @@ mod tests {
15871584
let secondary = ArtifactComparisonSummary::summarize(secondary_comparisons);
15881585

15891586
let mut result = String::new();
1590-
write_summary_table(&primary, &secondary, true, &mut result);
1591-
assert_eq!(result, expected);
1587+
write_summary_table(&primary, &secondary, true, true, &mut result);
1588+
let header = "| (instructions:u) | mean[^1] | max | count[^2] |\n|:----------------:|:--------:|:---:|:---------:|\n";
1589+
assert_eq!(result, format!("{header}{expected}"));
15921590
}
15931591
}

site/src/github/comparison_summary.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ fn write_metric_summary(
214214
)
215215
.unwrap();
216216

217-
write_summary_table(&primary, &secondary, true, message);
217+
write_summary_table(&primary, &secondary, true, false, message);
218218

219219
if hidden {
220220
message.push_str("</details>\n");

0 commit comments

Comments
 (0)