1717
1818final readonly class MarkdownRenderer implements RendererInterface
1919{
20+ private const array COMPACT_HEADERS = ['Benchmark ' , 'Set ' , 'Mem. Peak ' , 'Time ' , 'Variability ' ];
21+
22+ private const array COMPACT_SOURCE_COLUMNS = ['benchmark ' , 'subject ' , 'set ' , 'mem_peak ' , 'mode ' , 'rstdev ' ];
23+
2024 public function __construct (
2125 private OutputInterface $ output ,
2226 private Printer $ printer ,
@@ -71,11 +75,14 @@ private function renderTable(Table $table): array
7175 return $ lines ;
7276 }
7377
78+ $ rows = array_map ($ this ->renderTableRow (...), $ table ->rows ());
79+ [$ columns , $ rows ] = $ this ->compactAggregateReportTable ($ columns , $ rows );
80+
7481 $ lines [] = $ this ->renderRow ($ columns );
7582 $ lines [] = $ this ->renderSeparatorRow ($ columns );
7683
77- foreach ($ table as $ row ) {
78- $ lines [] = $ this ->renderDataRow ($ row );
84+ foreach ($ rows as $ row ) {
85+ $ lines [] = $ this ->renderRow ($ row );
7986 }
8087
8188 $ lines [] = '' ;
@@ -96,11 +103,52 @@ private function renderSeparatorRow(array $columns): string
96103 ));
97104 }
98105
99- private function renderDataRow (TableRow $ row ): string
106+ private function renderTableRow (TableRow $ row ): array
107+ {
108+ return array_values (array_map ($ this ->formatCell (...), iterator_to_array ($ row )));
109+ }
110+
111+ private function compactAggregateReportTable (array $ columns , array $ rows ): array
112+ {
113+ $ columnIndexes = $ this ->resolveCompactSourceColumnIndexes ($ columns );
114+
115+ if ($ columnIndexes === null ) {
116+ return [$ columns , $ rows ];
117+ }
118+
119+ $ rows = array_map (function (array $ row ) use ($ columnIndexes ): array {
120+ $ set = trim ((string ) $ row [$ columnIndexes ['set ' ]]);
121+
122+ return [
123+ sprintf ('%s(%s) ' , $ row [$ columnIndexes ['benchmark ' ]], $ row [$ columnIndexes ['subject ' ]]),
124+ $ set === '' ? '- ' : $ set ,
125+ $ row [$ columnIndexes ['mem_peak ' ]],
126+ $ row [$ columnIndexes ['mode ' ]],
127+ $ row [$ columnIndexes ['rstdev ' ]],
128+ ];
129+ }, $ rows );
130+
131+ return [self ::COMPACT_HEADERS , $ rows ];
132+ }
133+
134+ private function resolveCompactSourceColumnIndexes (array $ columns ): ?array
100135 {
101- $ cells = array_map ($ this ->formatCell (...), iterator_to_array ($ row ));
136+ $ columnIndexes = array_flip ($ columns );
137+
138+ foreach (self ::COMPACT_SOURCE_COLUMNS as $ column ) {
139+ if (! array_key_exists ($ column , $ columnIndexes )) {
140+ return null ;
141+ }
142+ }
102143
103- return $ this ->renderRow ($ cells );
144+ return [
145+ 'benchmark ' => $ columnIndexes ['benchmark ' ],
146+ 'subject ' => $ columnIndexes ['subject ' ],
147+ 'set ' => $ columnIndexes ['set ' ],
148+ 'mem_peak ' => $ columnIndexes ['mem_peak ' ],
149+ 'mode ' => $ columnIndexes ['mode ' ],
150+ 'rstdev ' => $ columnIndexes ['rstdev ' ],
151+ ];
104152 }
105153
106154 private function formatCell (Node $ node ): string
0 commit comments