Skip to content

Commit af7ef03

Browse files
committed
[benchmark] ReportFormatter: refactor header logic
Confine the logic for printing headers to the header function.
1 parent a998e18 commit af7ef03

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

benchmark/scripts/compare_perf_tests.py

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,15 @@ def justify_columns(contents):
628628
def row(contents):
629629
return COLUMN_SEPARATOR.join(justify_columns(contents)) + ' \n'
630630

631-
def header(header):
632-
return '\n' + row(header) + row([HEADER_SEPARATOR] * 5)
631+
def header(title, column_labels):
632+
h = ''
633+
if not self.header_printed:
634+
h = '\n' + row(column_labels) + row([HEADER_SEPARATOR] * 5)
635+
if self.single_table:
636+
h += row(('**' + title + '**', '', '', '', ''))
637+
if self.single_table and not self.header_printed:
638+
self.header_printed = True
639+
return h
633640

634641
def format_columns(r, is_strong):
635642
return (r if not is_strong else
@@ -640,25 +647,13 @@ def table(title, results, is_strong=False, is_open=False):
640647
row(format_columns(ReportFormatter.values(r), is_strong))
641648
for r in results
642649
]
643-
if not rows:
644-
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-
])
650+
table = (header(title if self.single_table else '',
651+
ReportFormatter.header_for(results[0])) +
652+
''.join(rows))
653+
return '' if not rows else (
654+
(table if self.single_table else
655+
DETAIL.format(
656+
title, len(results), table, 'open' if is_open else '')))
662657

663658
return ''.join([
664659
table('Regression', self.comparator.decreased, True, True),

0 commit comments

Comments
 (0)