Skip to content

Commit a998e18

Browse files
committed
[benchmark] ReportFormatter: faster templating
It is slightly faster to simply concatenate strings that don’t require special formatting.
1 parent 49d25bf commit a998e18

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

benchmark/scripts/compare_perf_tests.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -589,14 +589,14 @@ def values(result):
589589
def markdown(self):
590590
"""Report results of benchmark comparisons in Markdown format."""
591591
return self._formatted_text(
592-
ROW='{0} | {1} | {2} | {3} | {4} \n',
592+
COLUMN_SEPARATOR=' | ',
593593
HEADER_SEPARATOR='---',
594594
DETAIL=self.MARKDOWN_DETAIL)
595595

596596
def git(self):
597597
"""Report results of benchmark comparisons in 'git' format."""
598598
return self._formatted_text(
599-
ROW='{0} {1} {2} {3} {4} \n',
599+
COLUMN_SEPARATOR=' ',
600600
HEADER_SEPARATOR=' ',
601601
DETAIL=self.GIT_DETAIL)
602602

@@ -618,22 +618,22 @@ def max_widths(maximum, widths):
618618

619619
return reduce(max_widths, widths, [0] * 5)
620620

621-
def _formatted_text(self, ROW, HEADER_SEPARATOR, DETAIL):
621+
def _formatted_text(self, COLUMN_SEPARATOR, HEADER_SEPARATOR, DETAIL):
622622
widths = self._column_widths()
623623
self.header_printed = False
624624

625625
def justify_columns(contents):
626626
return [c.ljust(w) for w, c in zip(widths, contents)]
627627

628628
def row(contents):
629-
return ROW.format(*justify_columns(contents))
629+
return COLUMN_SEPARATOR.join(justify_columns(contents)) + ' \n'
630630

631631
def header(header):
632632
return '\n' + row(header) + row([HEADER_SEPARATOR] * 5)
633633

634-
def format_columns(r, strong):
635-
return (r if not strong else
636-
r[:-1] + ('**{0}**'.format(r[-1]), ))
634+
def format_columns(r, is_strong):
635+
return (r if not is_strong else
636+
r[:-1] + ('**' + r[-1] + '**', ))
637637

638638
def table(title, results, is_strong=False, is_open=False):
639639
rows = [

0 commit comments

Comments
 (0)