Skip to content

Commit 9636d7a

Browse files
authored
Merge pull request #1272 from rust-lang/summary-max-row
Correctly calculate largest change independent of its direction in PR summary table
2 parents bab9355 + 9639195 commit 9636d7a

File tree

1 file changed

+66
-11
lines changed

1 file changed

+66
-11
lines changed

‎site/src/comparison.rs

Lines changed: 66 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::db::{ArtifactId, Benchmark, Lookup, Profile, Scenario};
77
use crate::github;
88
use crate::load::SiteCtxt;
99
use crate::selector::{self, Tag};
10+
use std::cmp::Ordering;
1011

1112
use collector::Bound;
1213
use serde::Serialize;
@@ -501,14 +502,26 @@ pub fn write_summary_table(
501502
let largest_change = if primary.is_empty() {
502503
"N/A".to_string()
503504
} else {
504-
let change = primary
505-
.most_relevant_changes()
506-
.iter()
507-
.fold(0.0, |accum: f64, item| {
508-
let change = item.map(|v| v.relative_change() * 100.0).unwrap_or(0.0);
509-
accum.max(change)
510-
});
511-
format!("{:.1}%", change)
505+
let largest_improvement = primary
506+
.largest_improvement()
507+
.map(|c| c.relative_change())
508+
.unwrap_or(0.0);
509+
let largest_regression = primary
510+
.largest_regression()
511+
.map(|c| c.relative_change())
512+
.unwrap_or(0.0);
513+
let change = if largest_improvement
514+
.abs()
515+
.partial_cmp(&largest_regression.abs())
516+
.unwrap_or(Ordering::Equal)
517+
!= Ordering::Less
518+
{
519+
largest_improvement
520+
} else {
521+
largest_regression
522+
};
523+
524+
format!("{:.1}%", change * 100.0)
512525
};
513526

514527
writeln!(
@@ -1317,7 +1330,7 @@ mod tests {
13171330
};
13181331

13191332
#[test]
1320-
fn summary_table_only_improvements_primary() {
1333+
fn summary_table_only_regressions_primary() {
13211334
check_table(
13221335
vec![
13231336
(Category::Primary, 5.0, 10.0),
@@ -1339,7 +1352,7 @@ mod tests {
13391352
}
13401353

13411354
#[test]
1342-
fn summary_table_only_regressions_primary() {
1355+
fn summary_table_only_improvements_primary() {
13431356
check_table(
13441357
vec![
13451358
(Category::Primary, 5.0, 2.0),
@@ -1351,7 +1364,7 @@ mod tests {
13511364
|:---:|:---:|:---:|:---:|:---:|:---:|
13521365
| count[^1] | 0 | 0 | 3 | 0 | 3 |
13531366
| mean[^2] | N/A | N/A | -71.7% | N/A | -71.7% |
1354-
| max | N/A | N/A | -80.0% | N/A | 0.0% |
1367+
| max | N/A | N/A | -80.0% | N/A | -80.0% |
13551368
13561369
[^1]: *number of relevant changes*
13571370
[^2]: *the arithmetic mean of the percent change*
@@ -1445,6 +1458,48 @@ mod tests {
14451458
| mean[^2] | 150.0% | 100.0% | -62.5% | -66.7% | 43.8% |
14461459
| max | 200.0% | 100.0% | -75.0% | -66.7% | 200.0% |
14471460
1461+
[^1]: *number of relevant changes*
1462+
[^2]: *the arithmetic mean of the percent change*
1463+
"#
1464+
.trim_start(),
1465+
);
1466+
}
1467+
1468+
#[test]
1469+
fn summary_table_mixed_largest_change_improvement() {
1470+
check_table(
1471+
vec![
1472+
(Category::Primary, 10.0, 5.0),
1473+
(Category::Primary, 5.0, 6.0),
1474+
],
1475+
r#"
1476+
| | Regressions 😿 <br />(primary) | Regressions 😿 <br />(secondary) | Improvements 🎉 <br />(primary) | Improvements 🎉 <br />(secondary) | All 😿 🎉 <br />(primary) |
1477+
|:---:|:---:|:---:|:---:|:---:|:---:|
1478+
| count[^1] | 1 | 0 | 1 | 0 | 2 |
1479+
| mean[^2] | 20.0% | N/A | -50.0% | N/A | -15.0% |
1480+
| max | 20.0% | N/A | -50.0% | N/A | -50.0% |
1481+
1482+
[^1]: *number of relevant changes*
1483+
[^2]: *the arithmetic mean of the percent change*
1484+
"#
1485+
.trim_start(),
1486+
);
1487+
}
1488+
1489+
#[test]
1490+
fn summary_table_mixed_largest_change_regression() {
1491+
check_table(
1492+
vec![
1493+
(Category::Primary, 5.0, 10.0),
1494+
(Category::Primary, 6.0, 5.0),
1495+
],
1496+
r#"
1497+
| | Regressions 😿 <br />(primary) | Regressions 😿 <br />(secondary) | Improvements 🎉 <br />(primary) | Improvements 🎉 <br />(secondary) | All 😿 🎉 <br />(primary) |
1498+
|:---:|:---:|:---:|:---:|:---:|:---:|
1499+
| count[^1] | 1 | 0 | 1 | 0 | 2 |
1500+
| mean[^2] | 100.0% | N/A | -16.7% | N/A | 41.7% |
1501+
| max | 100.0% | N/A | -16.7% | N/A | 100.0% |
1502+
14481503
[^1]: *number of relevant changes*
14491504
[^2]: *the arithmetic mean of the percent change*
14501505
"#

0 commit comments

Comments
 (0)