Skip to content

Commit 4d511a5

Browse files
committed
Make summary table vertical
1 parent 87d51ce commit 4d511a5

File tree

1 file changed

+59
-50
lines changed

1 file changed

+59
-50
lines changed

site/src/comparison.rs

Lines changed: 59 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -476,55 +476,23 @@ pub fn write_summary_table(
476476
let value = if count > 0 { calculate() } else { None };
477477
value
478478
.map(|value| format!("{value:.1}%"))
479-
.unwrap_or_else(|| "N/A".to_string())
479+
.unwrap_or_else(|| "".to_string())
480480
}
481481

482-
let columns = [
483-
" ", // we want at least 10 spaces to accommodate "count[^1]"
484-
"Regressions 😿 <br />(primary)",
485-
"Regressions 😿 <br />(secondary)",
486-
"Improvements 🎉 <br />(primary)",
487-
"Improvements 🎉 <br />(secondary)",
488-
"All 😿 🎉 <br />(primary)",
489-
];
490-
let counts: Vec<usize> = columns
491-
.iter()
492-
.map(|s| {
493-
// Unicode emojis usually have width equal to ~2 chars (maybe? :) ).
494-
let count = s.chars().count();
495-
if s.chars().any(|c| !c.is_whitespace()) {
496-
count + 1
497-
} else {
498-
count
499-
}
500-
})
501-
.collect();
502-
for column in &columns {
503-
write!(result, "| {} ", column).unwrap();
504-
}
505-
result.push_str("|\n");
506-
for &count in &counts {
507-
write!(result, "|:{}:", "-".repeat(count)).unwrap();
508-
}
509-
result.push_str("|\n");
482+
// (label, mean, max, count)
483+
let mut column_data = vec![];
510484

511-
let mut render_row = |row: Vec<String>| {
512-
debug_assert_eq!(row.len(), columns.len());
513-
for (column, &count) in row.into_iter().zip(&counts) {
514-
write!(result, "| {:<1$} ", column, count).unwrap();
515-
}
516-
result.push_str("|\n");
517-
};
518-
render_row(vec![
519-
format!("count{}", if with_footnotes { "[^1]" } else { "" }),
520-
primary.num_regressions.to_string(),
521-
secondary.num_regressions.to_string(),
522-
primary.num_improvements.to_string(),
523-
secondary.num_improvements.to_string(),
524-
(primary.num_regressions + primary.num_improvements).to_string(),
485+
// label
486+
column_data.push(vec![
487+
"Worse (primary)".to_string(),
488+
"Worse (secondary)".to_string(),
489+
"Better (primary)".to_string(),
490+
"Better (secondary)".to_string(),
491+
"All (primary)".to_string(),
525492
]);
526-
render_row(vec![
527-
format!("mean{}", if with_footnotes { "[^2]" } else { "" }),
493+
494+
// mean
495+
column_data.push(vec![
528496
render_stat(primary.num_regressions, || {
529497
Some(primary.arithmetic_mean_of_regressions())
530498
}),
@@ -538,7 +506,7 @@ pub fn write_summary_table(
538506
Some(secondary.arithmetic_mean_of_improvements())
539507
}),
540508
if primary.is_empty() {
541-
"N/A".to_string()
509+
"".to_string()
542510
} else {
543511
format!("{:.1}%", primary.arithmetic_mean_of_changes())
544512
},
@@ -569,8 +537,8 @@ pub fn write_summary_table(
569537
format!("{:.1}%", change * 100.0)
570538
};
571539

572-
render_row(vec![
573-
"max".to_string(),
540+
// max
541+
column_data.push(vec![
574542
render_stat(primary.num_regressions, || {
575543
primary
576544
.largest_regression()
@@ -593,14 +561,55 @@ pub fn write_summary_table(
593561
}),
594562
largest_change,
595563
]);
564+
565+
// count
566+
column_data.push(vec![
567+
primary.num_regressions.to_string(),
568+
secondary.num_regressions.to_string(),
569+
primary.num_improvements.to_string(),
570+
secondary.num_improvements.to_string(),
571+
(primary.num_regressions + primary.num_improvements).to_string(),
572+
]);
573+
574+
let column_labels = [
575+
" ".to_string(), // we want at least 10 spaces to accommodate "count[^2]"
576+
format!("mean{}", if with_footnotes { "[^1]" } else { "" }),
577+
"max".to_string(),
578+
format!("count{}", if with_footnotes { "[^2]" } else { "" }),
579+
];
580+
let counts: Vec<usize> = column_labels.iter().map(|s| s.chars().count()).collect();
581+
for column in &column_labels {
582+
write!(result, "| {} ", column).unwrap();
583+
}
584+
result.push_str("|\n");
585+
for &count in &counts {
586+
write!(result, "|:{}:", "-".repeat(count)).unwrap();
587+
}
588+
result.push_str("|\n");
589+
590+
let mut render_row = |row: Vec<String>| {
591+
debug_assert_eq!(row.len(), column_labels.len());
592+
for (column, &count) in row.into_iter().zip(&counts) {
593+
write!(result, "| {:<1$} ", column, count).unwrap();
594+
}
595+
result.push_str("|\n");
596+
};
597+
598+
for row in 0..5 {
599+
let row_data = column_data
600+
.iter()
601+
.map(|rows| rows[row].clone())
602+
.collect::<Vec<_>>();
603+
render_row(row_data);
604+
}
596605
}
597606

598607
pub fn write_summary_table_footer(result: &mut String) {
599608
writeln!(
600609
result,
601610
r#"
602-
[^1]: *number of relevant changes*
603-
[^2]: *the arithmetic mean of the percent change*"#
611+
[^1]: *the arithmetic mean of the percent change*
612+
[^2]: *number of relevant changes*"#
604613
)
605614
.unwrap();
606615
}

0 commit comments

Comments
 (0)