@@ -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 (
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 = ' | | | | \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 (
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}""" )
602
603
603
604
def _column_widths (self ):
604
605
changed = self .comparator .decreased + self .comparator .increased
@@ -614,53 +615,49 @@ def _column_widths(self):
614
615
]
615
616
616
617
def max_widths (maximum , widths ):
617
- return tuple ( map (max , zip (maximum , widths ) ))
618
+ return map (max , zip (maximum , widths ))
618
619
619
- return reduce (max_widths , widths , tuple ( [0 ] * 5 ) )
620
+ return reduce (max_widths , widths , [0 ] * 5 )
620
621
621
- def _formatted_text (self , ROW , 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
- return tuple ( [c .ljust (w ) for w , c in zip (widths , contents )])
628
+ return [c .ljust (w ) for w , c in zip (widths , contents )]
627
629
628
630
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 ] + '**' , ))
637
647
638
648
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 :
644
650
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 ([
664
661
table ('Regression' , self .comparator .decreased , True , True ),
665
662
table ('Improvement' , self .comparator .increased , True ),
666
663
('' if self .changes_only else
0 commit comments