The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Bencher::Manual::FAQ - FAQ for Bencher

VERSION

This document describes version 1.056 of Bencher::Manual::FAQ (from Perl distribution Bencher), released on 2021-08-13.

GENERAL

What is Bencher?

Bencher is a benchmark framework. It can be used to benchmark Perl code or external commands.

Why should I use Bencher (instead of Benchmark, Dumbbench, ...)?

The main point of Bencher is making your benchmark codes more reusable. Your benchmark codes are organized into participants and can be specified as templates. These codes then can be combined (permuted) with multiple datasets and can also be run using different perl versions and different module versions, all with specifying just a command-line option. You can select which participants or datasets or other permutation combinations to run. You can run the codes with the good ol' Benchmark.pm or using the default Benchmark::Dumb.

The results are put into a table data structure and can be formatted, split, saved/sent to server, or post-processed in other ways.

There are also tools available to chart the results, embed the results into your POD, and so on.

How do I use Bencher?

Bencher can be used via CLI or as a Perl library|Bencher::Backend.

See also extra CLI's in App::BencherUtils.

What is a scenario?

What is a participant?

What is a dataset?

BENCHMARKING PERL CODE

How do I run a participant in a minimal environment?

Normally when you benchmark a perl code using Bencher, it is run in the same process as Bencher framework (and the bencher CLI too, if you run Bencher from the CLI) itself. In some cases this is not desirable, for example you might want to run a perl code in absence of a module but said module is required and already loaded by Bencher.

In these cases, you can use a "perl command-line" participant type instead of "perl code" so that your code is run in its own perl interpreter process. For example, instead of:

 participants => [
     # testing speed when no adapter has been configured
     {code_template => 'state $log = do { require Log::Any; Log::Any->get_logger }; $log->trace("foo")'},
 ]

you write:

 participants => [
     # testing speed when no adapter has been configured
     {perl_cmdline_template => ['-MLog::Any', '-e', 'my $log = Log::Any->get_logger; $log->trace("foo") for 1..1_000_000']},
 ]

Note that when using "perl command-line" participant, the overhead of starting the perl interpreter and compiling your script is included in the benchmark time, so you might want to make that overhead relatively small compared to the time of running your code (hence the million-times loop in the second example above).

MULTIPLE PERLS

MULTIPLE MODULE VERSIONS

How do I permute module versions when I use "perl command-line" participant type?

You can set module path in PERL5OPT and permute using env_hashes. Example:

 env_hashes => [
     {PERL5OPT=>"-Ipath1"},
     {PERL5OPT=>"-Ipath2"},
 ],
 participants => [
     {perl_cmdline => ['-e', 'do_something()']},
 ],

BENCHMARKING EXTERNAL COMMANDS

BENCHMARKING PERL COMMANDS

HOMEPAGE

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

SOURCE

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

BUGS

Please report any bugs or feature requests on the bugtracker website 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.

SEE ALSO

Bencher::Manual::*

AUTHOR

perlancar <perlancar@cpan.org>

CONTRIBUTING

To contribute, you can send patches by email/via RT, or send pull requests on GitHub.

Most of the time, you don't need to build the distribution yourself. You can simply modify the code, then test via:

 % prove -l

If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla plugin and/or Pod::Weaver::Plugin. Any additional steps required beyond that are considered a bug and can be reported to me.

COPYRIGHT AND LICENSE

This software is copyright (c) 2021, 2020, 2019, 2018, 2017, 2016, 2015 by perlancar <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.