Skip to content

Commit d1a1ed1

Browse files
authored
Merge pull request #25027 from palimondo/single-table++
2 parents b1b6ce6 + 007d398 commit d1a1ed1

File tree

3 files changed

+80
-53
lines changed

3 files changed

+80
-53
lines changed

benchmark/scripts/compare_perf_tests.py

Lines changed: 48 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -547,15 +547,6 @@ def __init__(self, comparator, changes_only,
547547
self.changes_only = changes_only
548548
self.single_table = single_table
549549

550-
MARKDOWN_DETAIL = """
551-
<details {3}>
552-
<summary>{0} ({1})</summary>
553-
{2}
554-
</details>
555-
"""
556-
GIT_DETAIL = """
557-
{0} ({1}): {2}"""
558-
559550
PERFORMANCE_TEST_RESULT_HEADER = ('TEST', 'MIN', 'MAX', 'MEAN', 'MAX_RSS')
560551
RESULT_COMPARISON_HEADER = ('TEST', 'OLD', 'NEW', 'DELTA', 'RATIO')
561552

@@ -589,16 +580,26 @@ def values(result):
589580
def markdown(self):
590581
"""Report results of benchmark comparisons in Markdown format."""
591582
return self._formatted_text(
592-
ROW='{0} | {1} | {2} | {3} | {4} \n',
593-
HEADER_SEPARATOR='---',
594-
DETAIL=self.MARKDOWN_DETAIL)
583+
label_formatter=lambda s: ('**' + s + '**'),
584+
COLUMN_SEPARATOR=' | ',
585+
DELIMITER_ROW=([':---'] + ['---:'] * 4),
586+
SEPARATOR='&nbsp; | | | | \n',
587+
SECTION="""
588+
<details {3}>
589+
<summary>{0} ({1})</summary>
590+
{2}
591+
</details>
592+
""")
595593

596594
def git(self):
597595
"""Report results of benchmark comparisons in 'git' format."""
598596
return self._formatted_text(
599-
ROW='{0} {1} {2} {3} {4} \n',
600-
HEADER_SEPARATOR=' ',
601-
DETAIL=self.GIT_DETAIL)
597+
label_formatter=lambda s: s.upper(),
598+
COLUMN_SEPARATOR=' ',
599+
DELIMITER_ROW=None,
600+
SEPARATOR='\n',
601+
SECTION="""
602+
{0} ({1}): \n{2}""")
602603

603604
def _column_widths(self):
604605
changed = self.comparator.decreased + self.comparator.increased
@@ -614,53 +615,49 @@ def _column_widths(self):
614615
]
615616

616617
def max_widths(maximum, widths):
617-
return tuple(map(max, zip(maximum, widths)))
618+
return map(max, zip(maximum, widths))
618619

619-
return reduce(max_widths, widths, tuple([0] * 5))
620+
return reduce(max_widths, widths, [0] * 5)
620621

621-
def _formatted_text(self, ROW, HEADER_SEPARATOR, DETAIL):
622+
def _formatted_text(self, label_formatter, COLUMN_SEPARATOR,
623+
DELIMITER_ROW, SEPARATOR, SECTION):
622624
widths = self._column_widths()
623625
self.header_printed = False
624626

625627
def justify_columns(contents):
626-
return tuple([c.ljust(w) for w, c in zip(widths, contents)])
628+
return [c.ljust(w) for w, c in zip(widths, contents)]
627629

628630
def row(contents):
629-
return ROW.format(*justify_columns(contents))
630-
631-
def header(header):
632-
return '\n' + row(header) + row(tuple([HEADER_SEPARATOR] * 5))
633-
634-
def format_columns(r, strong):
635-
return (r if not strong else
636-
r[:-1] + ('**{0}**'.format(r[-1]), ))
631+
return ('' if not contents else
632+
COLUMN_SEPARATOR.join(justify_columns(contents)) + '\n')
633+
634+
def header(title, column_labels):
635+
labels = (column_labels if not self.single_table else
636+
map(label_formatter, (title, ) + column_labels[1:]))
637+
h = (('' if not self.header_printed else SEPARATOR) +
638+
row(labels) +
639+
(row(DELIMITER_ROW) if not self.header_printed else ''))
640+
if self.single_table and not self.header_printed:
641+
self.header_printed = True
642+
return h
643+
644+
def format_columns(r, is_strong):
645+
return (r if not is_strong else
646+
r[:-1] + ('**' + r[-1] + '**', ))
637647

638648
def table(title, results, is_strong=False, is_open=False):
639-
rows = [
640-
row(format_columns(ReportFormatter.values(r), is_strong))
641-
for r in results
642-
]
643-
if not rows:
649+
if not results:
644650
return ''
645-
646-
if self.single_table:
647-
t = ''
648-
if not self.header_printed:
649-
t += header(ReportFormatter.header_for(results[0]))
650-
self.header_printed = True
651-
t += row(('**' + title + '**', '', '', '', ''))
652-
t += ''.join(rows)
653-
return t
654-
655-
return DETAIL.format(
656-
*[
657-
title, len(results),
658-
(header(ReportFormatter.header_for(results[0])) +
659-
''.join(rows)),
660-
('open' if is_open else '')
661-
])
662-
663-
return ''.join([
651+
rows = [row(format_columns(ReportFormatter.values(r), is_strong))
652+
for r in results]
653+
table = (header(title if self.single_table else '',
654+
ReportFormatter.header_for(results[0])) +
655+
''.join(rows))
656+
return (table if self.single_table else
657+
SECTION.format(
658+
title, len(results), table, 'open' if is_open else ''))
659+
660+
return '\n' + ''.join([
664661
table('Regression', self.comparator.decreased, True, True),
665662
table('Improvement', self.comparator.increased, True),
666663
('' if self.changes_only else

benchmark/scripts/run_smoke_bench

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def main():
8888
help='In addition to stdout, write the results into a markdown file')
8989
argparser.add_argument(
9090
'-threshold', type=float,
91-
help='The performance threshold in % which triggers a re-run',
91+
help='The performance threshold in %% which triggers a re-run',
9292
default=5)
9393
argparser.add_argument(
9494
'-num-samples', type=int,

benchmark/scripts/test_compare_perf_tests.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ def test_column_headers(self):
759759
)
760760
self.assert_markdown_contains([
761761
'TEST | OLD | NEW | DELTA | RATIO',
762-
'--- | --- | --- | --- | --- ',
762+
':--- | ---: | ---: | ---: | ---: ',
763763
'TEST | MIN | MAX | MEAN | MAX_RSS'])
764764
self.assert_git_contains([
765765
'TEST OLD NEW DELTA RATIO',
@@ -855,6 +855,36 @@ def test_report_only_changes(self):
855855
self.assertNotIn('No Changes', html)
856856
self.assertNotIn('AngryPhonebook', html)
857857

858+
def test_single_table_report(self):
859+
"""Single table report has inline headers and no elaborate sections."""
860+
self.tc.removed = [] # test handling empty section
861+
rf = ReportFormatter(self.tc, changes_only=True, single_table=True)
862+
markdown = rf.markdown()
863+
self.assertNotIn('<details', markdown) # no sections
864+
self.assertNotIn('\n\n', markdown) # table must not be broken
865+
self.assertNotIn('Removed', markdown)
866+
self.assert_report_contains([
867+
'\n**Regression** ',
868+
'| **OLD**', '| **NEW**', '| **DELTA**', '| **RATIO**',
869+
'\n**Added** ',
870+
'| **MIN**', '| **MAX**', '| **MEAN**', '| **MAX_RSS**'
871+
], markdown)
872+
# Single delimiter row:
873+
self.assertIn('\n:---', markdown) # first column is left aligned
874+
self.assertEqual(markdown.count('| ---:'), 4) # other, right aligned
875+
# Separator before every inline header (new section):
876+
self.assertEqual(markdown.count('&nbsp; | | | | '), 2)
877+
878+
git = rf.git()
879+
self.assertNotIn('): \n', git) # no sections
880+
self.assertNotIn('REMOVED', git)
881+
self.assert_report_contains([
882+
'\nREGRESSION ', ' OLD ', ' NEW ', ' DELTA ', ' RATIO ',
883+
'\n\nADDED ', ' MIN ', ' MAX ', ' MEAN ', ' MAX_RSS '
884+
], git)
885+
# Separator before every inline header (new section):
886+
self.assertEqual(git.count('\n\n'), 2)
887+
858888

859889
class Test_parse_args(unittest.TestCase):
860890
required = ['--old-file', 'old.log', '--new-file', 'new.log']

0 commit comments

Comments
 (0)