Skip to content
Merged
Changes from 1 commit
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
31 changes: 13 additions & 18 deletions site/src/comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,16 @@ pub fn write_summary_table(
with_footnotes: bool,
result: &mut String,
) {
let metric = match primary
.relevant_comparisons
.first()
.or(secondary.relevant_comparisons.first())
.map(|m| m.metric.as_str())
{
Some(m) => m,
None => return,
};

fn render_stat<F: FnOnce() -> Option<f64>>(count: usize, calculate: F) -> String {
let value = if count > 0 { calculate() } else { None };
value
Expand Down Expand Up @@ -627,7 +637,7 @@ pub fn write_summary_table(
// This code attempts to space the table cells evenly so that the data is
// easy to read for anyone who is viewing the Markdown source.
let column_labels = [
" ".to_string(), // we want at least 10 spaces to accommodate "count[^2]"
format!("({metric})",),
format!("mean{}", if with_footnotes { "[^1]" } else { "" }),
"max".to_string(),
format!("count{}", if with_footnotes { "[^2]" } else { "" }),
Expand Down Expand Up @@ -1383,8 +1393,6 @@ mod tests {
(Category::Primary, 1.0, 3.0),
],
r#"
| | mean[^1] | max | count[^2] |
|:----------:|:--------:|:---:|:---------:|
| Regressions ❌ <br /> (primary) | 146.7% | 200.0% | 3 |
| Regressions ❌ <br /> (secondary) | - | - | 0 |
| Improvements ✅ <br /> (primary) | - | - | 0 |
Expand All @@ -1404,8 +1412,6 @@ mod tests {
(Category::Primary, 4.0, 1.0),
],
r#"
| | mean[^1] | max | count[^2] |
|:----------:|:--------:|:---:|:---------:|
| Regressions ❌ <br /> (primary) | - | - | 0 |
| Regressions ❌ <br /> (secondary) | - | - | 0 |
| Improvements ✅ <br /> (primary) | -71.7% | -80.0% | 3 |
Expand All @@ -1425,8 +1431,6 @@ mod tests {
(Category::Secondary, 4.0, 1.0),
],
r#"
| | mean[^1] | max | count[^2] |
|:----------:|:--------:|:---:|:---------:|
| Regressions ❌ <br /> (primary) | - | - | 0 |
| Regressions ❌ <br /> (secondary) | - | - | 0 |
| Improvements ✅ <br /> (primary) | - | - | 0 |
Expand All @@ -1446,8 +1450,6 @@ mod tests {
(Category::Secondary, 1.0, 3.0),
],
r#"
| | mean[^1] | max | count[^2] |
|:----------:|:--------:|:---:|:---------:|
| Regressions ❌ <br /> (primary) | - | - | 0 |
| Regressions ❌ <br /> (secondary) | 146.7% | 200.0% | 3 |
| Improvements ✅ <br /> (primary) | - | - | 0 |
Expand All @@ -1468,8 +1470,6 @@ mod tests {
(Category::Primary, 4.0, 1.0),
],
r#"
| | mean[^1] | max | count[^2] |
|:----------:|:--------:|:---:|:---------:|
| Regressions ❌ <br /> (primary) | 150.0% | 200.0% | 2 |
| Regressions ❌ <br /> (secondary) | - | - | 0 |
| Improvements ✅ <br /> (primary) | -62.5% | -75.0% | 2 |
Expand All @@ -1492,8 +1492,6 @@ mod tests {
(Category::Primary, 4.0, 1.0),
],
r#"
| | mean[^1] | max | count[^2] |
|:----------:|:--------:|:---:|:---------:|
| Regressions ❌ <br /> (primary) | 150.0% | 200.0% | 2 |
| Regressions ❌ <br /> (secondary) | 100.0% | 100.0% | 1 |
| Improvements ✅ <br /> (primary) | -62.5% | -75.0% | 2 |
Expand All @@ -1512,8 +1510,6 @@ mod tests {
(Category::Primary, 5.0, 6.0),
],
r#"
| | mean[^1] | max | count[^2] |
|:----------:|:--------:|:---:|:---------:|
| Regressions ❌ <br /> (primary) | 20.0% | 20.0% | 1 |
| Regressions ❌ <br /> (secondary) | - | - | 0 |
| Improvements ✅ <br /> (primary) | -50.0% | -50.0% | 1 |
Expand All @@ -1532,8 +1528,6 @@ mod tests {
(Category::Primary, 6.0, 5.0),
],
r#"
| | mean[^1] | max | count[^2] |
|:----------:|:--------:|:---:|:---------:|
| Regressions ❌ <br /> (primary) | 100.0% | 100.0% | 1 |
| Regressions ❌ <br /> (secondary) | - | - | 0 |
| Improvements ✅ <br /> (primary) | -16.7% | -16.7% | 1 |
Expand Down Expand Up @@ -1588,6 +1582,7 @@ mod tests {

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