#!perl

our $DATE = '2016-01-08'; # DATE
our $VERSION = '0.26'; # VERSION

use 5.010001;
use strict;
use warnings;

use Perinci::CmdLine::Any;

binmode(STDOUT, ":utf8");
Perinci::CmdLine::Any->new(
    url => '/Bencher/bencher',
    log => 1,
    pass_cmdline_object => 1,
)->run;

# ABSTRACT: A benchmark framework (CLI)
# PODNAME: bencher

__END__

=pod

=encoding UTF-8

=head1 NAME

bencher - A benchmark framework (CLI)

=head1 VERSION

This document describes version 0.26 of bencher (from Perl distribution Bencher), released on 2016-01-08.

=head1 SYNOPSIS

List all scenario modules (Bencher::Scenario::*) installed locally on your
system:

 % bencher --list-scenario-modules
 % bencher -L

Run benchmark described by a scenario module:

 % bencher -m Example

Run benchmark described by a scenario file:

 % bencher -f scenario.pl

Add participants from the command-line instead of (or in addition to) those
specified in a scenario file/module:

 % bencher -p '{"fcall_template":"Bar::func(<arg>)"}'

Run module startup overhead benchmark instead of the normal benchmark:

 % bencher -m Example --module-startup

Show/dump scenario instead of running benchmark:

 % bencher -m Example --show-scenario

List participants instead of running benchmark:

 % bencher ... --list-participants

List datasets instead of running benchmark:

 % bencher ... --list-datasets

List items instead of running benchmark:

 % bencher ... --list-items

Show items' results instead of running benchmark:

 % bencher ... --show-items-results

Select (include/exclude) participants before running benchmark (you can also
select datasets/modules/items):

 % bencher ... --include-participant-pattern 'Tiny|Lite' --exclude-participant 'HTTP::Tiny'

=head1 DESCRIPTION

=head1 OPTIONS

C<*> marks required options.

=head2 Action options

=over

=item B<--action>=I<s>, B<-a>

Default value:

 "bench"

Valid values:

 ["list-scenario-modules","show-scenario","list-participants","list-participant-modules","list-datasets","list-items","show-items-results","bench"]

=item B<--list-datasets>

Shortcut for -a list-datasets.

See C<--action>.

=item B<--list-items>

Shortcut for -a list-items.

See C<--action>.

=item B<--list-participant-modules>

Shortcut for -a list-participant-modules.

See C<--action>.

=item B<--list-participants>

Shortcut for -a list-participants.

See C<--action>.

=item B<--list-permutes>

Shortcut for -a list-permutes.

See C<--action>.

=item B<--list-scenario-modules>

Shortcut for -a list-scenario-modules.

See C<--action>.

=item B<--module-startup>

Benchmark module startup overhead instead of normal benchmark.

=item B<--show-items-results>

Shortcut for -a show-items-results.

See C<--action>.

=item B<--show-scenario>

Shortcut for -a show-scenario.

See C<--action>.

=item B<-L>

Shortcut for -a list-scenario-modules.

See C<--action>.

=back

=head2 Configuration options

=over

=item B<--config-path>=I<filename>

Set path to configuration file.

Can be specified multiple times.

=item B<--config-profile>=I<s>

Set configuration profile to use.

=item B<--no-config>

Do not use any configuration file.

=back

=head2 Environment options

=over

=item B<--no-env>

Do not read environment for default options.

=back

=head2 Filtering options

=over

=item B<--exclude-dataset-pattern>=I<s>

Exclude datasets matching this regex pattern.

=item B<--exclude-dataset-tag>=I<s@>

Add a tag to dataset exclude tag list.

You can specify `A & B` to exclude datasets that have _both_ tags A and B.


Can be specified multiple times.

=item B<--exclude-dataset-tags-json>=I<s>

Exclude datasets whose tag matches this (JSON-encoded).

See C<--exclude-dataset-tag>.

=item B<--exclude-dataset>=I<s@>

Add dataset to exclude list.

Can be specified multiple times.

=item B<--exclude-datasets-json>=I<s>

Exclude datasets whose seq/name matches this (JSON-encoded).

See C<--exclude-dataset>.

=item B<--exclude-function-pattern>=I<s>

Exclude function(s) matching this regex pattern.

=item B<--exclude-function>=I<s@>

Add function to exclude list.

Can be specified multiple times.

=item B<--exclude-functions-json>=I<s>

Exclude functions specified in this list (JSON-encoded).

See C<--exclude-function>.

=item B<--exclude-item-pattern>=I<s>

Exclude items matching this regex pattern.

=item B<--exclude-item>=I<s@>

Add item to exclude list.

Can be specified multiple times.

=item B<--exclude-items-json>=I<s>

Exclude items whose seq/name matches this (JSON-encoded).

See C<--exclude-item>.

=item B<--exclude-module-pattern>=I<s>

Exclude module(s) matching this regex pattern.

=item B<--exclude-module>=I<s@>

Add module to exclude list.

Can be specified multiple times.

=item B<--exclude-modules-json>=I<s>

Exclude modules specified in this list (JSON-encoded).

See C<--exclude-module>.

=item B<--exclude-participant-pattern>=I<s>

Exclude participants matching this regex pattern.

=item B<--exclude-participant-tag>=I<s@>

Add a tag to participants exclude tag list.

You can specify `A & B` to exclude participants that have _both_ tags A and B.


Can be specified multiple times.

=item B<--exclude-participant-tags-json>=I<s>

Exclude participants whose tag matches this (JSON-encoded).

See C<--exclude-participant-tag>.

=item B<--exclude-participant>=I<s@>

Add participant to include list.

Can be specified multiple times.

=item B<--exclude-participants-json>=I<s>

Exclude participants whose seq/name matches this (JSON-encoded).

See C<--exclude-participant>.

=item B<--include-dataset-pattern>=I<s>

Only include datasets matching this regex pattern.

=item B<--include-dataset-tag>=I<s@>

Add a tag to dataset include tag list.

You can specify `A & B` to include datasets that have _both_ tags A and B.


Can be specified multiple times.

=item B<--include-dataset-tags-json>=I<s>

Only include datasets whose tag matches this (JSON-encoded).

See C<--include-dataset-tag>.

=item B<--include-dataset>=I<s@>

Add dataset to include list.

Can be specified multiple times.

=item B<--include-datasets-json>=I<s>

Only include datasets whose seq/name matches this (JSON-encoded).

See C<--include-dataset>.

=item B<--include-function-pattern>=I<s>

Only include functions matching this regex pattern.

=item B<--include-function>=I<s@>

Add function to include list.

Can be specified multiple times.

=item B<--include-functions-json>=I<s>

Only include functions specified in this list (JSON-encoded).

See C<--include-function>.

=item B<--include-item-pattern>=I<s>

Only include items matching this regex pattern.

=item B<--include-item>=I<s@>

Add item to include list.

Can be specified multiple times.

=item B<--include-items-json>=I<s>

Only include items whose seq/name matches this (JSON-encoded).

See C<--include-item>.

=item B<--include-module-pattern>=I<s>

Only include modules matching this regex pattern.

=item B<--include-module>=I<s@>

Add module to include list.

Can be specified multiple times.

=item B<--include-modules-json>=I<s>

Only include modules specified in this list (JSON-encoded).

See C<--include-module>.

=item B<--include-participant-pattern>=I<s>

Only include participants matching this regex pattern.

=item B<--include-participant-tag>=I<s@>

Add a tag to participants include tag list.

You can specify `A & B` to include participants that have _both_ tags A and B.


Can be specified multiple times.

=item B<--include-participant-tags-json>=I<s>

Only include participants whose tag matches this (JSON-encoded).

See C<--include-participant-tag>.

=item B<--include-participant>=I<s@>

Add participant to include list.

Can be specified multiple times.

=item B<--include-participants-json>=I<s>

Only include participants whose seq/name matches this (JSON-encoded).

See C<--include-participant>.

=back

=head2 Logging options

=over

=item B<--debug>

Set log level to debug (note: you also need to set LOG=1 to enable logging, or use DEBUG=1).

=item B<--log-level>=I<s>

Set log level (note: you also need to set LOG=1 to enable logging).

=item B<--quiet>

Set log level to quiet (note: you also need to set LOG=1 to enable logging, or use QUIET=1).

=item B<--trace>

Set log level to trace (note: you also need to set LOG=1 to enable logging, or use TRACE=1).

=item B<--verbose>

Set log level to info (note: you also need to set LOG=1 to enable logging, or use VERBOSE=1).

=back

=head2 Output options

=over

=item B<--format>=I<s>

Choose output format, e.g. json, text.

Default value:

 undef

=item B<--json>

Set output format to json.

=item B<--naked-res>

When outputing as JSON, strip result envelope.

Default value:

 0

By default, when outputing as JSON, the full enveloped result is returned, e.g.:

    [200,"OK",[1,2,3],{"func.extra"=>4}]

The reason is so you can get the status (1st element), status message (2nd
element) as well as result metadata/extra result (4th element) instead of just
the result (3rd element). However, sometimes you want just the result, e.g. when
you want to pipe the result for more post-processing. In this case you can use
`--naked-res` so you just get:

    [1,2,3]


=back

=head2 Other options

=over

=item B<--dataset>=I<s>

Add a dataset.

See C<--datasets>.

=item B<--datasets-json>=I<s>

Add datasets (JSON-encoded).

See C<--datasets>.

=item B<--datasets>=I<s>

Add datasets.

=item B<--detail>, B<-l>

=item B<--help>, B<-h>, B<-?>

Display help message and exit.

=item B<--on-failure>=I<s>

What to do when command fails or Perl code dies.

Valid values:

 ["die","skip"]

The default is "die". When set to "skip", will first run the code of each item
before benchmarking and trap command failure/Perl exception and if that happens,
will "skip" the item.


=item B<--participant>=I<s>

Add a participant.

See C<--participants>.

=item B<--participants-json>=I<s>

Add participants (JSON-encoded).

See C<--participants>.

=item B<--participants>=I<s>

Add participants.

=item B<--precision-limit>=I<f>

Set maximum (=smallest number) precision.

Instead of setting `precision` which forces a single value, you can also set
this `precision_limit` setting. If the precision in the scenario is higher
(=number is smaller) than this limit, then this limit is used. For example, if
the scenario specifies `default_precision` 0.001 and `precision_limit` is set to
0.005 then 0.005 is used.

This setting is useful on slower computers which might not be able to reach the
required precision before hitting maximum number of iterations.


=item B<--precision>=I<f>

Precision, will be passed to Benchmark::Dumb.

This setting overrides `default_precision` property in the scenario.


=item B<--raw>

Show "raw" data.

When action=show-items-result, will print result as-is instead of dumping as
Perl.


=item B<--scenario-file>=I<s>, B<-f>

Load a scenario from a Perl file.

Perl file will be do()'ed and the last expression should be a hash containing
the scenario specification.


=item B<--scenario-module>=I<s>, B<-m>

Load a scenario from a Bencher::Scenario:: Perl module.

Will try to load module `Bencher::Scenario::<NAME>` and expect to find a package
variable in the module called `$scenario` which should be a hashref containing
the scenario specification.


=item B<--version>, B<-v>

Display program's version and exit.

=item B<-d>=I<s>

Add a dataset.

See C<--datasets>.

=item B<-p>=I<s>

Add a participant.

See C<--participants>.

=back

=head1 SEE ALSO

L<Bencher>

=head1 COMPLETION

This script has shell tab completion capability with support for several
shells.

=head2 bash

To activate bash completion for this script, put:

 complete -C bencher bencher

in your bash startup (e.g. C<~/.bashrc>). Your next shell session will then
recognize tab completion for the command. Or, you can also directly execute the
line above in your shell to activate immediately.

It is recommended, however, that you install L<shcompgen> which allows you to
activate completion scripts for several kinds of scripts on multiple shells.
Some CPAN distributions (those that are built with
L<Dist::Zilla::Plugin::GenShellCompletion>) will even automatically enable shell
completion for their included scripts (using C<shcompgen>) at installation time,
so you can immadiately have tab completion.

=head2 tcsh

To activate tcsh completion for this script, put:

 complete bencher 'p/*/`bencher`/'

in your tcsh startup (e.g. C<~/.tcshrc>). Your next shell session will then
recognize tab completion for the command. Or, you can also directly execute the
line above in your shell to activate immediately.

It is also recommended to install C<shcompgen> (see above).

=head2 other shells

For fish and zsh, install C<shcompgen> as described above.

=head1 ENVIRONMENT

=head2 BENCHER_OPT => str

Specify additional command-line options

=head1 CONFIGURATION FILE

This script can read configuration file, which by default is searched at C<~/.config/bencher.conf>, C<~/bencher.conf> or C</etc/bencher.conf> (can be changed by specifying C<--config-path>). All found files will be read and merged.

To disable searching for configuration files, pass C<--no-config>.

Configuration file is in the format of L<IOD>, which is basically INI with some extra features. 

You can put multiple profiles in a single file by using section names like C<[profile=SOMENAME]>. Those sections will only be read if you specify the matching C<--config-profile SOMENAME>.

List of available configuration parameters:

 action (see --action)
 datasets (see --datasets)
 detail (see --detail)
 exclude_dataset_pattern (see --exclude-dataset-pattern)
 exclude_dataset_tags (see --exclude-dataset-tag)
 exclude_datasets (see --exclude-dataset)
 exclude_function_pattern (see --exclude-function-pattern)
 exclude_functions (see --exclude-function)
 exclude_item_pattern (see --exclude-item-pattern)
 exclude_items (see --exclude-item)
 exclude_module_pattern (see --exclude-module-pattern)
 exclude_modules (see --exclude-module)
 exclude_participant_pattern (see --exclude-participant-pattern)
 exclude_participant_tags (see --exclude-participant-tag)
 exclude_participants (see --exclude-participant)
 format (see --format)
 include_dataset_pattern (see --include-dataset-pattern)
 include_dataset_tags (see --include-dataset-tag)
 include_datasets (see --include-dataset)
 include_function_pattern (see --include-function-pattern)
 include_functions (see --include-function)
 include_item_pattern (see --include-item-pattern)
 include_items (see --include-item)
 include_module_pattern (see --include-module-pattern)
 include_modules (see --include-module)
 include_participant_pattern (see --include-participant-pattern)
 include_participant_tags (see --include-participant-tag)
 include_participants (see --include-participant)
 log_level (see --log-level)
 module_startup (see --module-startup)
 naked_res (see --naked-res)
 on_failure (see --on-failure)
 participants (see --participants)
 precision (see --precision)
 precision_limit (see --precision-limit)
 raw (see --raw)
 scenario_file (see --scenario-file)
 scenario_module (see --scenario-module)

=head1 FILES

~/.config/bencher.conf

~/bencher.conf

/etc/bencher.conf

=head1 HOMEPAGE

Please visit the project's homepage at L<https://metacpan.org/release/Bencher>.

=head1 SOURCE

Source repository is at L<https://github.com/perlancar/perl-Bencher>.

=head1 BUGS

Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Bencher>

When submitting a bug or request, please include a test-file or a
patch to an existing test-file that illustrates the bug or desired
feature.

=head1 AUTHOR

perlancar <perlancar@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2016 by perlancar@cpan.org.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut
