Benchmark-Command

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

          can ruin the benchmark result. Previously this was not displayed by
          default because by default program's output is stripped. Now the
          default behavior is to *not* strip program's output, unless the
          'quiet' option is set to true.

        [ENHANCEMENTS]

        - Add option: ignore_exit_code. Now a non-zero exit code will cause the
          benchmark to die, unless we set this option to true.

        - Add per-command options: ignore_exit_code, skip_not_found.

        - Tweak examples and other minor fixes.


0.04    2015-04-10 (PERLANCAR)

	- Add option: debug; by default strip programs' output unless in
	  debug mode.


0.03    2015-04-09 (PERLANCAR)

        - Allow specifying per-command option (first element of command
          arrayref). Known per-command options: env.

        - Allow specifying coderef command, which will be used as-is.


0.02    2015-04-09 (PERLANCAR)

	- Add option: skip_not_found.

	- Change wording in Description.


0.01    2015-04-09 (PERLANCAR)

        - First release.

README  view on Meta::CPAN


      * quiet => bool (default: from env QUIET or 0)

      If set to true, will hide program's output.

      * ignore_exit_code => bool (default: from env
      BENCHMARK_COMMAND_IGNORE_EXIT_CODE or 0)

      If set to true, will not die if exit code is non-zero.

      * skip_not_found => bool (default: 0)

      If set to true, will skip benchmarking commands where the program is
      not found. The default bahavior is to die.

    Known per-command options:

      * env => hash

      Locally set environment variables for the command.

      * ignore_exit_code => bool

      This overrides global ignore_exit_code option.

      * skip_not_found => bool

      This overrides global skip_not_found option.

ENVIRONMENT

 BENCHMARK_COMMAND_COUNT => num

    Set default for run()'s $count argument.

 BENCHMARK_COMMAND_IGNORE_EXIT_CODE => bool

    Set default for run()'s ignore_exit_code option.

 BENCHMARK_COMMAND_QUIET => bool

    Set default for run()'s quiet option (takes precedence of QUIET).

 BENCHMARK_COMMAND_SKIP_NOT_FOUND => bool

    Set default for run()'s skip_not_found option.

 QUIET => bool

    Set default for run()'s quiet option (if BENCHMARK_COMMAND_QUIET is not
    defined).

 SEE ALSO

    Benchmark::Apps

lib/Benchmark/Command.pm  view on Meta::CPAN

use File::Which;

sub run {
    my ($count, $cmds, $opts) = @_;

    $count //= $ENV{BENCHMARK_COMMAND_COUNT} // 0;

    $opts //= {};
    $opts->{quiet} //= $ENV{BENCHMARK_COMMAND_QUIET} // $ENV{QUIET} // 0;
    $opts->{ignore_exit_code} //= $ENV{BENCHMARK_COMMAND_IGNORE_EXIT_CODE} // 0;
    $opts->{skip_not_found} //= $ENV{BENCHMARK_COMMAND_SKIP_NOT_FOUND} // 0;

    ref($cmds) eq 'HASH' or die "cmds must be a hashref";

    my $subs = {};
    my $longest = 0;
  COMMAND:
    for my $cmd_name (keys %$cmds) {
        $longest = length($cmd_name) if length($cmd_name) > $longest;
        my $cmd_spec = $cmds->{$cmd_name};
        if (ref($cmd_spec) eq 'CODE') {

lib/Benchmark/Command.pm  view on Meta::CPAN

        my $per_cmd_opts;
        if (ref($cmd[0]) eq 'HASH') {
            $per_cmd_opts = shift @cmd;
        } else {
            $per_cmd_opts = {};
        }
        $per_cmd_opts->{env} //= {};
        @cmd or die "cmds->{$cmd_name} must not be empty";

        unless (which $cmd[0]) {
            if ($per_cmd_opts->{skip_not_found} // $opts->{skip_not_found}) {
                warn "cmds->{$cmd_name}: program '$cmd[0]' not found, ".
                    "skipped\n";
                next COMMAND;
            } else {
                die "cmds->{$cmd_name}: program '$cmd[0]' not found";
            }
        }

        # XXX we haven't counted for overhead of setting/resetting env vars. but
        # because it should be about 3 orders of magnitude (microsecs instead of

lib/Benchmark/Command.pm  view on Meta::CPAN

=over

=item * quiet => bool (default: from env QUIET or 0)

If set to true, will hide program's output.

=item * ignore_exit_code => bool (default: from env BENCHMARK_COMMAND_IGNORE_EXIT_CODE or 0)

If set to true, will not die if exit code is non-zero.

=item * skip_not_found => bool (default: 0)

If set to true, will skip benchmarking commands where the program is not found.
The default bahavior is to die.

=back

Known per-command options:

=over

=item * env => hash

Locally set environment variables for the command.

=item * ignore_exit_code => bool

This overrides global C<ignore_exit_code> option.

=item * skip_not_found => bool

This overrides global C<skip_not_found> option.

=back

=head1 ENVIRONMENT

=head2 BENCHMARK_COMMAND_COUNT => num

Set default for C<run()>'s C<$count> argument.

=head2 BENCHMARK_COMMAND_IGNORE_EXIT_CODE => bool

Set default for C<run()>'s C<ignore_exit_code> option.

=head2 BENCHMARK_COMMAND_QUIET => bool

Set default for C<run()>'s C<quiet> option (takes precedence of C<QUIET>).

=head2 BENCHMARK_COMMAND_SKIP_NOT_FOUND => bool

Set default for C<run()>'s C<skip_not_found> option.

=head2 QUIET => bool

Set default for C<run()>'s C<quiet> option (if C<BENCHMARK_COMMAND_QUIET> is not
defined).

=head2 SEE ALSO

L<Benchmark::Apps>



( run in 0.274 second using v1.01-cache-2.11-cpan-4d4bc49f3ae )