Skip to content

Commit

Permalink
[benchmark] ReportFormatter: refactor header logic
Browse files Browse the repository at this point in the history
Confine the logic for printing headers to the header function.
  • Loading branch information
palimondo committed May 23, 2019
1 parent a998e18 commit af7ef03
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions benchmark/scripts/compare_perf_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,8 +628,15 @@ def justify_columns(contents):
def row(contents):
return COLUMN_SEPARATOR.join(justify_columns(contents)) + ' \n'

def header(header):
return '\n' + row(header) + row([HEADER_SEPARATOR] * 5)
def header(title, column_labels):
h = ''
if not self.header_printed:
h = '\n' + row(column_labels) + row([HEADER_SEPARATOR] * 5)
if self.single_table:
h += row(('**' + title + '**', '', '', '', ''))
if self.single_table and not self.header_printed:
self.header_printed = True
return h

def format_columns(r, is_strong):
return (r if not is_strong else
Expand All @@ -640,25 +647,13 @@ def table(title, results, is_strong=False, is_open=False):
row(format_columns(ReportFormatter.values(r), is_strong))
for r in results
]
if not rows:
return ''

if self.single_table:
t = ''
if not self.header_printed:
t += header(ReportFormatter.header_for(results[0]))
self.header_printed = True
t += row(('**' + title + '**', '', '', '', ''))
t += ''.join(rows)
return t

return DETAIL.format(
*[
title, len(results),
(header(ReportFormatter.header_for(results[0])) +
''.join(rows)),
('open' if is_open else '')
])
table = (header(title if self.single_table else '',
ReportFormatter.header_for(results[0])) +
''.join(rows))
return '' if not rows else (
(table if self.single_table else
DETAIL.format(
title, len(results), table, 'open' if is_open else '')))

return ''.join([
table('Regression', self.comparator.decreased, True, True),
Expand Down

0 comments on commit af7ef03

Please sign in to comment.