Skip to content

Commit 03c3480

Browse files
author
Geoffrey Broadwell
committed
Add json output format
1 parent 869b42b commit 03c3480

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

bench

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use List::Util 'min', 'max';
1313
use List::MoreUtils 'uniq';
1414
use Capture::Tiny 'capture';
1515
use FindBin;
16+
use JSON;
1617
use Cwd;
1718

1819

@@ -184,6 +185,7 @@ my %TESTS = (
184185
],
185186
);
186187
my %FORMATTER = (
188+
json => \&summarize_results_json,
187189
text => \&summarize_results_text,
188190
html => \&summarize_results_html,
189191
html_snippet => \&summarize_results_html_snippet,
@@ -359,6 +361,14 @@ sub compare_times {
359361
return \%relative;
360362
}
361363

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+
362372
sub summarize_results_text {
363373
my ($times, $style) = @_;
364374

@@ -555,7 +565,7 @@ bench -- Benchmark Perl-family compilers against each other
555565
556566
=head1 SYNOPSIS
557567
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]
559569
560570
561571
=head1 DESCRIPTION
@@ -584,12 +594,13 @@ Get basic help for this program
584594
585595
Display this program's entire manpage
586596
587-
=item --format=text|html|html_snippet
597+
=item --format=text|json|html|html_snippet
588598
589599
Format the summary output in a particular format. The default is C<text>,
590600
which outputs a text-rendered summary table with ANSI coloring. HTML output
591601
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.
593604
594605
=item --style=0|1|auto
595606
@@ -600,7 +611,8 @@ highlight entries in the summary table; C<auto> turns on ANSI color whenever
600611
the output is a TTY. For HTML output, this determines whether a CSS style
601612
block is added to the HTML (element C<class> attributes are always output).
602613
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>).
604616
605617
=back
606618

0 commit comments

Comments
 (0)