@@ -547,15 +547,6 @@ def __init__(self, comparator, changes_only,
547
547
self .changes_only = changes_only
548
548
self .single_table = single_table
549
549
550
- MARKDOWN_DETAIL = """
551
- <details {3}>
552
- <summary>{0} ({1})</summary>
553
- {2}
554
- </details>
555
- """
556
- GIT_DETAIL = """
557
- {0} ({1}): {2}"""
558
-
559
550
PERFORMANCE_TEST_RESULT_HEADER = ('TEST' , 'MIN' , 'MAX' , 'MEAN' , 'MAX_RSS' )
560
551
RESULT_COMPARISON_HEADER = ('TEST' , 'OLD' , 'NEW' , 'DELTA' , 'RATIO' )
561
552
@@ -589,16 +580,26 @@ def values(result):
589
580
def markdown (self ):
590
581
"""Report results of benchmark comparisons in Markdown format."""
591
582
return self ._formatted_text (
583
+ label_formatter = lambda s : ('**' + s + '**' ),
592
584
COLUMN_SEPARATOR = ' | ' ,
593
- HEADER_SEPARATOR = '---' ,
594
- DETAIL = self .MARKDOWN_DETAIL )
585
+ DELIMITER_ROW = ([':---' ] + ['---:' ] * 4 ),
586
+ SEPARATOR = ' | | | | \n ' ,
587
+ SECTION = """
588
+ <details {3}>
589
+ <summary>{0} ({1})</summary>
590
+ {2}
591
+ </details>
592
+ """ )
595
593
596
594
def git (self ):
597
595
"""Report results of benchmark comparisons in 'git' format."""
598
596
return self ._formatted_text (
597
+ label_formatter = lambda s : s .upper (),
599
598
COLUMN_SEPARATOR = ' ' ,
600
- HEADER_SEPARATOR = ' ' ,
601
- DETAIL = self .GIT_DETAIL )
599
+ DELIMITER_ROW = None ,
600
+ SEPARATOR = '\n ' ,
601
+ SECTION = """
602
+ {0} ({1}): \n {2}""" )
602
603
603
604
def _column_widths (self ):
604
605
changed = self .comparator .decreased + self .comparator .increased
@@ -618,24 +619,24 @@ def max_widths(maximum, widths):
618
619
619
620
return reduce (max_widths , widths , [0 ] * 5 )
620
621
621
- def _formatted_text (self , COLUMN_SEPARATOR , HEADER_SEPARATOR , DETAIL ):
622
+ def _formatted_text (self , label_formatter , COLUMN_SEPARATOR ,
623
+ DELIMITER_ROW , SEPARATOR , SECTION ):
622
624
widths = self ._column_widths ()
623
625
self .header_printed = False
624
626
625
627
def justify_columns (contents ):
626
628
return [c .ljust (w ) for w , c in zip (widths , contents )]
627
629
628
630
def row (contents ):
629
- return COLUMN_SEPARATOR .join (justify_columns (contents )) + ' \n '
631
+ return ('' if not contents else
632
+ COLUMN_SEPARATOR .join (justify_columns (contents )) + '\n ' )
630
633
631
634
def header (title , column_labels ):
632
- h = ''
633
- if not self .header_printed :
634
- h = '\n ' + row (column_labels )
635
- h += row ([':' + HEADER_SEPARATOR ] + # left align 1st column
636
- ([HEADER_SEPARATOR + ':' ]) * 4 ) # right align rest
637
- if self .single_table :
638
- h += row (('**' + title + '**' , '' , '' , '' , '' ))
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 '' ))
639
640
if self .single_table and not self .header_printed :
640
641
self .header_printed = True
641
642
return h
@@ -645,19 +646,20 @@ def format_columns(r, is_strong):
645
646
r [:- 1 ] + ('**' + r [- 1 ] + '**' , ))
646
647
647
648
def table (title , results , is_strong = False , is_open = False ):
649
+ if not results :
650
+ return ''
648
651
rows = [
649
652
row (format_columns (ReportFormatter .values (r ), is_strong ))
650
653
for r in results
651
654
]
652
655
table = (header (title if self .single_table else '' ,
653
656
ReportFormatter .header_for (results [0 ])) +
654
657
'' .join (rows ))
655
- return '' if not rows else (
656
- (table if self .single_table else
657
- DETAIL .format (
658
- title , len (results ), table , 'open' if is_open else '' )))
658
+ return (table if self .single_table else
659
+ SECTION .format (
660
+ title , len (results ), table , 'open' if is_open else '' ))
659
661
660
- return '' .join ([
662
+ return '\n ' + ' ' .join ([
661
663
table ('Regression' , self .comparator .decreased , True , True ),
662
664
table ('Improvement' , self .comparator .increased , True ),
663
665
('' if self .changes_only else
0 commit comments