@@ -13,6 +13,7 @@ use List::Util 'min', 'max';
13
13
use List::MoreUtils ' uniq' ;
14
14
use Capture::Tiny ' capture' ;
15
15
use FindBin;
16
+ use JSON;
16
17
use Cwd;
17
18
18
19
@@ -184,6 +185,7 @@ my %TESTS = (
184
185
],
185
186
);
186
187
my %FORMATTER = (
188
+ json => \&summarize_results_json,
187
189
text => \&summarize_results_text,
188
190
html => \&summarize_results_html,
189
191
html_snippet => \&summarize_results_html_snippet,
@@ -359,6 +361,14 @@ sub compare_times {
359
361
return \%relative ;
360
362
}
361
363
364
+ sub summarize_results_json {
365
+ my $times = shift ;
366
+
367
+ my $json = JSON-> new-> utf8-> pretty-> encode($times );
368
+
369
+ print $json ;
370
+ }
371
+
362
372
sub summarize_results_text {
363
373
my ($times , $style ) = @_ ;
364
374
@@ -555,7 +565,7 @@ bench -- Benchmark Perl-family compilers against each other
555
565
556
566
=head1 SYNOPSIS
557
567
558
- bench [--help |-h |-?] [--man ] [--format = text|html|html_snippet ] [--style = 0|1|auto ]
568
+ bench [--help |-h |-?] [--man ] [--format = text|json| html|html_snippet ] [--style = 0|1|auto ]
559
569
560
570
561
571
=head1 DESCRIPTION
@@ -584,12 +594,13 @@ Get basic help for this program
584
594
585
595
Display this program's entire manpage
586
596
587
- =item --format=text |html |html_snippet
597
+ =item --format=text |json| html |html_snippet
588
598
589
599
Format the summary output in a particular format. The default is C<text > ,
590
600
which outputs a text-rendered summary table with ANSI coloring. HTML output
591
601
is also available, either in full document form (C<html > ), or just a snippet
592
- containing the summary table (C<html_snippet> ).
602
+ containing the summary table (C<html_snippet> ). To save the results in
603
+ computer-friendly form , use the C<json> format.
593
604
594
605
=item --style=0|1|auto
595
606
@@ -600,7 +611,8 @@ highlight entries in the summary table; C<auto> turns on ANSI color whenever
600
611
the output is a TTY. For HTML output , this determines whether a CSS style
601
612
block is added to the HTML (element C<class> attributes are always output ).
602
613
C<auto> defaults to adding CSS to full HTML documents (format C<html > ), and
603
- I<not> adding it to HTML snippets (format C<html_snippet> ).
614
+ I<not> adding it to HTML snippets (format C<html_snippet> ). Style settings
615
+ are ignored for JSON output (format <json> ).
604
616
605
617
=back
606
618
0 commit comments