@@ -476,55 +476,23 @@ pub fn write_summary_table(
476
476
let value = if count > 0 { calculate ( ) } else { None } ;
477
477
value
478
478
. map ( |value| format ! ( "{value:.1}%" ) )
479
- . unwrap_or_else ( || "N/A " . to_string ( ) )
479
+ . unwrap_or_else ( || "" . to_string ( ) )
480
480
}
481
481
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 ! [ ] ;
510
484
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( ) ,
525
492
] ) ;
526
- render_row ( vec ! [
527
- format!( "mean{}" , if with_footnotes { "[^2]" } else { "" } ) ,
493
+
494
+ // mean
495
+ column_data. push ( vec ! [
528
496
render_stat( primary. num_regressions, || {
529
497
Some ( primary. arithmetic_mean_of_regressions( ) )
530
498
} ) ,
@@ -538,7 +506,7 @@ pub fn write_summary_table(
538
506
Some ( secondary. arithmetic_mean_of_improvements( ) )
539
507
} ) ,
540
508
if primary. is_empty( ) {
541
- "N/A " . to_string( )
509
+ "" . to_string( )
542
510
} else {
543
511
format!( "{:.1}%" , primary. arithmetic_mean_of_changes( ) )
544
512
} ,
@@ -569,8 +537,8 @@ pub fn write_summary_table(
569
537
format ! ( "{:.1}%" , change * 100.0 )
570
538
} ;
571
539
572
- render_row ( vec ! [
573
- "max" . to_string ( ) ,
540
+ // max
541
+ column_data . push ( vec ! [
574
542
render_stat( primary. num_regressions, || {
575
543
primary
576
544
. largest_regression( )
@@ -593,14 +561,55 @@ pub fn write_summary_table(
593
561
} ) ,
594
562
largest_change,
595
563
] ) ;
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
+ }
596
605
}
597
606
598
607
pub fn write_summary_table_footer ( result : & mut String ) {
599
608
writeln ! (
600
609
result,
601
610
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 *"#
604
613
)
605
614
. unwrap ( ) ;
606
615
}
0 commit comments