NAME
bencher - A benchmark framework (CLI)
VERSION
This document describes version 1.062.4 of bencher (from Perl distribution Bencher), released on 2024-02-19.
SYNOPSIS
bencher [--action=str|-L|-a=str|--dump-items|--dump-parsed-scenario|--list-datasets|--list-items|--list-participant-modules|--list-participants|--list-perls|--list-permutes|--list-scenario-modules|--profile|--show-items-codes|--show-items-outputs|--show-items-results|--show-items-results-sizes|--show-scenario] [--capture-stderr|--no-capture-stderr|--nocapture-stderr] [--capture-stdout|--no-capture-stdout|--nocapture-stdout] [--code-startup] [--config-path=path|-c|--no-config|-C] [--config-profile=profile|-P] [--cpanmodules-module=perl::modname] [--datasets=hash|-d=hash|--dataset=hash] [--debug|--log-level=level|--quiet|--trace|--verbose] [--detail|-l|--no-detail|--nodetail] [--env-hashes=hash|--env-hash=hash] [(--exclude-dataset-name=str)+] [--exclude-dataset-pattern=re] [(--exclude-dataset-seq=int)+] [(--exclude-dataset-tag=str)+] [(--exclude-dataset=str)+] [--exclude-function-pattern=re] [(--exclude-function=str)+] [(--exclude-item-name=str)+] [--exclude-item-pattern=re] [(--exclude-item-seq=int)+] [(--exclude-item=str)+] [--exclude-module-pattern=re] [(--exclude-module=str)+] [(--exclude-participant-name=str)+] [--exclude-participant-pattern=re] [(--exclude-participant-seq=int)+] [(--exclude-participant-tag=str)+] [(--exclude-participant=str)+] [(--exclude-perl=str)+] [--exclude-pp-modules|--nopp] [--exclude-xs-modules|--noxs] [--format=name|--json] [(--include-dataset-name=str)+] [--include-dataset-pattern=re] [(--include-dataset-seq=int)+] [(--include-dataset-tag=str)+] [(--include-dataset=str)+] [--include-function-pattern=re] [(--include-function=str)+] [(--include-item-name=str)+] [--include-item-pattern=re] [(--include-item-seq=int)+] [(--include-item=str)+] [--include-module-pattern=re] [(--include-module=str)+] [(--include-participant-name=str)+] [--include-participant-pattern=re] [(--include-participant-seq=int)+] [(--include-participant-tag=str)+] [(--include-participant=str)+] [(--include-path=str)+|(-I=str)+] [(--include-perl=str)+] [--keep-tempdir|--no-keep-tempdir|--nokeep-tempdir] [--module-startup] [--multimodver=perl::modname] [--multiperl|--no-multiperl|--nomultiperl] [--(no)naked-res] [--no-env] [--note=str] [--on-failure=str] [--on-result-failure=str] [--page-result[=program]|--view-result[=program]] [--participants=hash|-p=hash|--participant=hash] [--precision-limit=float] [--precision=float] [--raw|--no-raw|--noraw] [--render-as-benchmark-pm|-B] [--result-dir=dirname] [--result-filename=filename] [--return-meta|--no-return-meta|--noreturn-meta] [--runner=str] [--save-result|--no-save-result|--nosave-result] [--scenario-file=str|-f=str] [--scenario-module=perl::modname|-m=perl::modname] [--scenario=s] [--scientific-notation] [(--sort=str)+] [--test|--no-test|--notest] [--tidy|--no-tidy|--notidy] [--with-args-size|--without-args-size] [--with-process-size|--without-process-size] [--with-result-size|--without-result-size]
Getting started and basic usage
To benchmark things, you write a scenario file. Let's write a simple one that benchmarks several trim functions. In scenario.pl:
#!/usr/bin/env perl
use strict;
use warnings;
our $scenario = {
participants => [
{fcall_template=>'String::Trim::NonRegex::trim(<str>)'},
{fcall_template=>'String::Trim::Regex::trim(<str>)'},
{fcall_template=>'Text::Minify::XS::minify_ascii(<str>)'},
],
datasets => [
{name=>'empty' , args=>{str=>''}},
{name=>'len10ws1' , args=>{str=>' '.('x' x 10).' '}},
{name=>'len100ws1' , args=>{str=>' '.('x' x 100).' '}},
],
};
The scenario is declared in package variable $scenario
. In the above script, we define three participants (function/code that will be benchmarked) and three datasets (arguments to functions): an empty string, a 10-character string surrounded by two spaces, and a 100-character string surrounded by two spaces.
You'll notice that the participant is a string (a code template) instead of coderef. Bencher can benchmark coderef, but by using a code template, we can permute the code with different datasets into benchmark items (each item is the actual benchmark code that will be run). (For more terminologies and concepts, see Bencher, but the abovementioned terms are pretty much all the important ones.)
Next, run the scenario (do the benchmarking):
% bencher -f scenario.pl
# Run on: perl v5.34.0, CPU Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz (2 cores), OS GNU/Linux Ubuntu version 20.04, OS kernel: Linux version 5.4.0-91-generic
# Elapsed time: 0.29s
+--------------------------------+-----------+-----------+-----------+-----------------------+-----------------------+---------+---------+
| participant | dataset | rate (/s) | time (μs) | pct_faster_vs_slowest | pct_slower_vs_fastest | errors | samples |
+--------------------------------+-----------+-----------+-----------+-----------------------+-----------------------+---------+---------+
| String::Trim::Regex::trim | len100ws1 | 165330 | 6.04851 | 0.00% | 4531.91% | 5.4e-12 | 20 |
| String::Trim::Regex::trim | len10ws1 | 862720 | 1.1591 | 421.82% | 787.65% | 5.7e-12 | 24 |
| String::Trim::NonRegex::trim | len100ws1 | 1048000 | 0.9539 | 534.07% | 630.51% | 1.7e-11 | 20 |
| String::Trim::NonRegex::trim | len10ws1 | 1060000 | 0.946 | 539.58% | 624.21% | 4.2e-10 | 20 |
| String::Trim::NonRegex::trim | empty | 1580000 | 0.633 | 856.02% | 384.50% | 1.9e-10 | 24 |
| Text::Minify::XS::minify_ascii | len100ws1 | 2737000 | 0.3653 | 1555.73% | 179.75% | 5.8e-12 | 20 |
| Text::Minify::XS::minify_ascii | len10ws1 | 6640000 | 0.1506 | 3916.37% | 15.33% | 5.7e-12 | 20 |
| String::Trim::Regex::trim | empty | 7100000 | 0.14 | 4180.07% | 8.22% | 1.6e-10 | 20 |
| Text::Minify::XS::minify_ascii | empty | 7700000 | 0.13 | 4531.91% | 0.00% | 2.6e-10 | 20 |
+--------------------------------+-----------+-----------+-----------+-----------------------+-----------------------+---------+---------+
From the result, we see that String::Trim::Regex is slower than String::Trim::NonRegex. But both are obliterated by Text::Minify::XS, which is no surprise since it is an XS module.
You'll notice that the benchmark runs pretty quickly because it uses Benchmark::Dumb by default, so each code only needs to be run a few times instead of seconds-long like with Benchmark.pm. You'll also notice the output is in table form, showing the code from slowest to fastest. If you prefer the Benchmark.pm matrix output, use the -B
option:
% bencher -f scenario.pl -B
# Run on: perl v5.34.0, CPU Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz (2 cores), OS GNU/Linux Ubuntu version 20.04, OS kernel: Linux version 5.4.0-91-generic
# Elapsed time: 0.20s
Rate STR:t len100ws1 STR:t len10ws1 STN:t len100ws1 STN:t len10ws1 STN:t empty TMX:m_a len100ws1 TMX:m_a len10ws1 STR:t empty TMX:m_a empty
STR:t len100ws1 155160/s -- -81% -85% -85% -90% -94% -97% -97% -98%
STR:t len10ws1 846000/s 446% -- -19% -19% -46% -68% -87% -88% -89%
STN:t len100ws1 1050000/s 576% 23% -- 0% -33% -61% -84% -85% -87%
STN:t len10ws1 1100000/s 578% 24% 0% -- -33% -61% -84% -85% -87%
STN:t empty 1600000/s 922% 87% 51% 50% -- -41% -76% -78% -80%
TMX:m_a len100ws1 2703000/s 1642% 219% 157% 156% 70% -- -59% -62% -67%
TMX:m_a len10ws1 6703000/s 4219% 690% 538% 536% 322% 147% -- -8% -19%
STR:t empty 7320000/s 4604% 761% 594% 593% 359% 169% 8% -- -11%
TMX:m_a empty 8277060/s 5234% 876% 687% 686% 421% 206% 23% 13% --
Legends:
STN:t empty: dataset=empty participant=String::Trim::NonRegex::trim
STN:t len100ws1: dataset=len100ws1 participant=String::Trim::NonRegex::trim
STN:t len10ws1: dataset=len10ws1 participant=String::Trim::NonRegex::trim
STR:t empty: dataset=empty participant=String::Trim::Regex::trim
STR:t len100ws1: dataset=len100ws1 participant=String::Trim::Regex::trim
STR:t len10ws1: dataset=len10ws1 participant=String::Trim::Regex::trim
TMX:m_a empty: dataset=empty participant=Text::Minify::XS::minify_ascii
TMX:m_a len100ws1: dataset=len100ws1 participant=Text::Minify::XS::minify_ascii
TMX:m_a len10ws1: dataset=len10ws1 participant=Text::Minify::XS::minify_ascii
To promote reusability, you can write scenarios in a Perl module, in the Bencher::Scenario::*
namespace. In fact, the above scenario (with more complete participants and datasets) is already on CPAN: Bencher::Scenario::StringFunctions::Trim. The examples below assume you have installed it (with e.g. cpanm -n
).
Doing other things with scenario
Listing participants
Let's see which participants (functions, in this case) are included in the scenario:
% bencher -m StringFunctions::Trim --list-participants
String::Trim::More::trim
String::Trim::NonRegex::trim
String::Trim::Regex::trim
String::Util::trim
Text::Minify::XS::minify
Listing datasets
What datasets are defined?
% bencher -m StringFunctions/Trim --list-datasets
empty
len10ws1
len100ws1
len100ws10
len100ws100
len1000ws1
len1000ws10
len1000ws100
len1000ws1000
Dumping the scenario
To see the scenario in more detail, let's dump it:
% bencher -m StringFunctions::Trim --dump-parsed-scenario
...
Showing codes and results
Let's see how the functions will trim the data len100ws10
:
% bencher -m StringFunctions/Trim --show-items-codes --include-dataset-name len10ws1
#0 (participant=String::Trim::More::trim):
package main; sub { String::Trim::More::trim(" xxxxxxxxxx ") }
#1 (participant=String::Trim::NonRegex::trim):
package main; sub { String::Trim::NonRegex::trim(" xxxxxxxxxx ") }
#2 (participant=String::Trim::Regex::trim):
package main; sub { String::Trim::Regex::trim(" xxxxxxxxxx ") }
#3 (participant=String::Util::trim):
package main; sub { String::Util::trim(" xxxxxxxxxx ") }
#4 (participant=Text::Minify::XS::minify):
package main; sub { Text::Minify::XS::minify(" xxxxxxxxxx ") }
Let's first check whether those functions do the job correctly:
% bencher -m StringFunctions/Trim --show-items-results --include-dataset-name len10ws1
#0 (participant=String::Trim::More::trim):
"xxxxxxxxxx"
#1 (participant=String::Trim::NonRegex::trim):
"xxxxxxxxxx"
#2 (participant=String::Trim::Regex::trim):
"xxxxxxxxxx"
#3 (participant=String::Util::trim):
"xxxxxxxxxx"
#4 (participant=Text::Minify::XS::minify):
"xxxxxxxxxx"
Selecting only certain participants and datasets
Let's benchmark trimming short strings:
% bencher -m StringFunctions/Trim --include-dataset-name len10ws1
# Run on: perl v5.34.0, CPU Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz (2 cores), OS GNU/Linux Ubuntu version 20.04, OS kernel: Linux version 5.4.0-91-generic
# Elapsed time: 0.13s
+------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
| participant | rate (/s) | time (ns) | pct_faster_vs_slowest | pct_slower_vs_fastest | errors | samples |
+------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
| String::Util::trim | 802126 | 1246.69 | 0.00% | 651.62% | 0 | 20 |
| String::Trim::Regex::trim | 813180 | 1229.7 | 1.38% | 641.40% | 1.1e-11 | 20 |
| String::Trim::NonRegex::trim | 971000 | 1030 | 21.07% | 520.80% | 3.5e-10 | 28 |
| String::Trim::More::trim | 1250860 | 799.448 | 55.94% | 381.98% | 0 | 20 |
| Text::Minify::XS::minify | 6030000 | 166 | 651.62% | 0.00% | 1.1e-10 | 20 |
+------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
Let's see how Text::Minify::XS::minify
perform on the different datasets:
% bencher -m StringFunctions/Trim --include-participant-name Text::Minify::XS::minify
# Run on: perl v5.34.0, CPU Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz (2 cores), OS GNU/Linux Ubuntu version 20.04, OS kernel: Linux version 5.4.0-91-generic
# Elapsed time: 0.18s
+---------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
| dataset | rate (/s) | time (μs) | pct_faster_vs_slowest | pct_slower_vs_fastest | errors | samples |
+---------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
| len1000ws1000 | 194823 | 5.13285 | 0.00% | 3974.38% | 0 | 20 |
| len1000ws100 | 426100 | 2.347 | 118.72% | 1762.85% | 3.9e-11 | 27 |
| len1000ws10 | 500000 | 2 | 154.42% | 1501.46% | 2.5e-09 | 20 |
| len1000ws1 | 520000 | 1.9 | 164.59% | 1439.91% | 6.4e-09 | 22 |
| len100ws100 | 1528000 | 0.6545 | 684.30% | 419.49% | 4.6e-11 | 20 |
| len100ws10 | 2690000 | 0.372 | 1279.83% | 195.28% | 4.6e-11 | 27 |
| len100ws1 | 2950000 | 0.339 | 1413.54% | 169.20% | 4.4e-11 | 20 |
| len10ws1 | 6130000 | 0.163 | 3045.75% | 29.52% | 1.1e-10 | 20 |
| empty | 7940000 | 0.126 | 3974.38% | 0.00% | 6.3e-11 | 30 |
+---------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
Showing result in raw form
The result data is actually a data structure. You can show it as JSON and save it somewhere:
% bencher -m StringFunctions/Trim --include-participant-name Text::Minify::XS::minify --format json
% bencher -m StringFunctions/Trim --include-participant-name Text::Minify::XS::minify --json ;# same thing
[
200,
"OK",
[
{
"dataset" : "empty",
"ds_tags" : "",
"errors" : 1.99650629822291e-10,
"notes" : "",
"p_tags" : "",
"participant" : "Text::Minify::XS::minify",
"perl" : "perl",
"rate" : 7666873.39865677,
"samples" : 34,
"seq" : 0,
"time" : 1.30431265524118e-07
},
...
Saving and redisplaying result
% bencher -m StringFunctions/Trim --include-participant-name Text::Minify::XS::minify --json > /path/to/result1.json
Later when you want to display it again, you can use bencher-fmt:
% bencher-fmt < /path/to/result1.json
Available subcommands
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
% bencher ... --list-participants -l ;# show detail
List participating Perl modules (modules mentioned by all the participants):
% bencher ... --list-participant-modules
% bencher ... --list-participant-modules -l ;# show detail
List datasets instead of running benchmark:
% bencher ... --list-datasets
% bencher ... --list-datasets -l ;# show detail
List items instead of running benchmark:
% bencher ... --list-items
% bencher ... --list-items -l ;# show detail
Show items' codes instead of running benchmark:
% bencher ... --show-items-codes
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'
Benchmarking against multiple perls
You need to install App::perlbrew first and then install some perls. Also, install at least Bencher::Backend to each perl you want to run the benchmark on.
To list available perls (same as perlbrew list
, but also shows whether a perl has Bencher):
% bencher --list-perls
% bencher --list-perls -l
To run a scenario against all perls which have Bencher:
% bencher -m ScenarioModule --multiperl ...
To run a scenario against some perls:
% bencher -m ScenarioModule --multiperl --include-perl perl-5.20.3 --include-perl perl-5.22.1 ...
Benchmarking multiple versions of a module
For example, if version 0.02 of a module is installed and you want to benchmark against version 0.01 (in /my/home/lib
):
% bencher -m ScenarioModule --multimodver Module::Name -I /my/home/lib ...
Note that Module::Name
must be among the modules that are being benchmarked (according to the scenario).
DESCRIPTION
Bencher is a benchmark framework. You specify a scenario (either in a Bencher::Scenario::*
Perl module, or a Perl script, or over the command-line) containing list of participants and datasets. Participants are codes or commands to run, and datasets are arguments for the codes/commands. Bencher will permute the participants and datasets into benchmark items, ready to run.
You can choose to include only some participants, datasets, or items. And there are options to view your scenario's participants/datasets/items/mentioned modules, run benchmark against multiple perls and module versions, and so on. Bencher comes as a CLI script as well as Perl module. See the Bencher::Backend documentation for more information.
OPTIONS
*
marks required options.
Main options
- --detail, -l
-
Show detailed information for each result.
- --env-hash=s
-
Add an environment hash.
See
--env-hashes
. - --env-hashes-json=s
-
Add environment hashes (JSON-encoded).
See
--env-hashes
. - --env-hashes=s
-
Add environment hashes.
- --on-failure=s
-
What to do when there is a failure.
Valid values:
["die","skip"]
For a command participant, failure means non-zero exit code. For a Perl-code participant, failure means Perl code dies or (if expected result is specified) the result is not equal to the expected result.
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.
- --on-result-failure=s
-
What to do when there is a result failure.
Valid values:
["die","skip","warn"]
This is like
on_failure
except that it specifically refer to the failure of item's result not being equal to expected result.There is an extra choice of
warn
for this type of failure, which is to print a warning to STDERR and continue. - --precision-limit=s
-
Set precision limit.
Instead of setting
precision
which forces a single value, you can also set thisprecision_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 specifiesdefault_precision
0.001 andprecision_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.
- --precision=s
-
Precision.
When benchmarking with the default Benchmark::Dumb runner, will pass the precision to it. The value is a fraction, e.g. 0.5 (for 5% precision), 0.01 (for 1% precision), and so on. Or, it can also be a positive integer to speciify minimum number of iterations, usually need to be at least 6 to avoid the "Number of initial runs is very small (<6)" warning. The default precision is 0, which is to let Benchmark::Dumb determine the precision, which is good enough for most cases.
When benchmarking with Benchmark runner, will pass this value as the
$count
argument. Which can be a positive integer to mean the number of iterations to do (e.g. 10, or 100). Or, can also be set to a negative number (e.g. -0.5 or -2) to mean minimum number of CPU seconds. The default is -0.5.When benchmarking with Benchmark::Dumb::SimpleTime, this value is a positive integer which means the number of iterations to perform.
When profiling, a number greater than 1 will set a repetition loop (e.g.
for(1..100){ ... }
).This setting overrides
default_precision
property in the scenario. - --runner=s
-
Runner module to use.
Valid values:
["Benchmark::Dumb","Benchmark","Benchmark::Dumb::SimpleTime"]
The default is
Benchmark::Dumb
which should be good enough for most cases.You can use
Benchmark
runner (Benchmark.pm
) if you are accustomed to it and want to see its output format.You can use
Benchmark::Dumb::SimpleTime
if your participant code runs for at least a few to many seconds and you want to use very few iterations (like 1 or 2) because you don't want to wait for too long. - --save-result
-
Whether to save benchmark result to file.
Will also be turned on automatically if
BENCHER_RESULT_DIR
environment variabl is defined.When this is turned on, will save a JSON file after benchmark, containing the result along with metadata. The directory of the JSON file will be determined from the
results_dir
option, while the filename from theresults_filename
option. - --test
-
Whether to test participant code once first before benchmarking.
By default, participant code is run once first for testing (e.g. whether it dies or return the correct result) before benchmarking. If your code runs for many seconds, you might want to skip this test and set this to 0.
- --with-args-size
-
Also return memory usage of item's arguments.
Memory size is measured using Devel::Size.
- --with-process-size
-
Also return process size information for each item.
This is done by dumping each item's code into a temporary file and running the file with a new perl interpreter process and measuring the process size at the end (so it does not need to load Bencher itself or the other items). Currently only works on Linux because process size information is retrieved from
/proc/PID/smaps
. Not all code can work, e.g. if the code tries to access a closure or outside data or extra modules (modules not specified in the participant or loaded by the code itself). Usually does not make sense to use this on external command participants. - --with-result-size
-
Also return memory usage of each item code's result (return value).
Memory size is measured using Devel::Size.
Action options
- --action=s, -a
-
Default value:
"bench"
Valid values:
["list-perls","list-scenario-modules","show-scenario","list-participants","list-participant-modules","list-datasets","list-items","show-items-codes","show-items-results","show-items-results-sizes","show-items-outputs","dump-items","dump-parsed-scenario","profile","bench"]
- --code-startup
-
Benchmark code startup overhead instead of normal benchmark.
- --dump-items
-
Shortcut for -a dump-items.
See
--action
. - --dump-parsed-scenario
-
Shortcut for -a dump-parsed-scenario.
See
--action
. - --list-datasets
-
Shortcut for -a list-datasets.
See
--action
. - --list-items
-
Shortcut for -a list-items.
See
--action
. - --list-participant-modules
-
Shortcut for -a list-participant-modules.
See
--action
. - --list-participants
-
Shortcut for -a list-participants.
See
--action
. - --list-perls
-
Shortcut for -a list-perls.
See
--action
. - --list-permutes
-
Shortcut for -a list-permutes.
See
--action
. - --list-scenario-modules
-
Shortcut for -a list-scenario-modules.
See
--action
. - --module-startup
-
Benchmark module startup overhead instead of normal benchmark.
- --profile
-
Shortcut for -a profile.
See
--action
. - --show-items-codes
-
Shortcut for -a show-items-codes.
See
--action
. - --show-items-outputs
-
Shortcut for -a show-items-outputs.
See
--action
. - --show-items-results
-
Shortcut for -a show-items-results.
See
--action
. - --show-items-results-sizes
-
Shortcut for -a show-items-results-sizes.
See
--action
. - --show-scenario
-
Shortcut for -a show-scenario.
See
--action
. - -L
-
Shortcut for -a list-scenario-modules.
See
--action
.
Configuration options
- --config-path=s, -c
-
Set path to configuration file.
Can actually be specified multiple times to instruct application to read from multiple configuration files (and merge them).
- --config-profile=s, -P
-
Set configuration profile to use.
A single configuration file can contain profiles, i.e. alternative sets of values that can be selected. For example:
[profile=dev] username=foo pass=beaver [profile=production] username=bar pass=honey
When you specify
--config-profile=dev
,username
will be set tofoo
andpassword
tobeaver
. When you specify--config-profile=production
,username
will be set tobar
andpassword
tohoney
. - --no-config, -C
-
Do not use any configuration file.
If you specify
--no-config
, the application will not read any configuration file.
Dataset options
- --dataset=s
-
Add a dataset.
See
--datasets
. - --datasets-json=s
-
Add datasets (JSON-encoded).
See
--datasets
. - --datasets=s
-
Add datasets.
- -d=s
-
Add a dataset.
See
--datasets
.
Debugging options
- --keep-tempdir
-
Do not cleanup temporary directory when bencher ends.
- --tidy
-
Run perltidy over generated scripts.
Environment options
- --no-env
-
Do not read environment for default options.
If you specify
--no-env
, the application wil not read any environment variable.
Filtering options
- --exclude-dataset-name=s@
-
Add dataset (by name) to exclude list.
Can be specified multiple times.
- --exclude-dataset-names-json=s
-
Exclude datasets whose name matches this (JSON-encoded).
See
--exclude-dataset-name
. - --exclude-dataset-pattern=s
-
Exclude datasets matching this regex pattern.
- --exclude-dataset-seq=s@
-
Add dataset (by sequence number) to exclude list.
Can be specified multiple times.
- --exclude-dataset-seqs-json=s
-
Exclude datasets whose sequence number matches this (JSON-encoded).
See
--exclude-dataset-seq
. - --exclude-dataset-tag=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.
-
Exclude datasets whose tag matches this (JSON-encoded).
See
--exclude-dataset-tag
. - --exclude-dataset=s@
-
Add dataset (by name/seq) to exclude list.
Can be specified multiple times.
- --exclude-datasets-json=s
-
Exclude datasets whose seq/name matches this (JSON-encoded).
See
--exclude-dataset
. - --exclude-function-pattern=s
-
Exclude function(s) matching this regex pattern.
- --exclude-function=s@
-
Add function to exclude list.
Can be specified multiple times.
- --exclude-functions-json=s
-
Exclude functions specified in this list (JSON-encoded).
See
--exclude-function
. - --exclude-item-name=s@
-
Add item (by name) to exclude list.
Can be specified multiple times.
- --exclude-item-names-json=s
-
Exclude items whose name matches this (JSON-encoded).
See
--exclude-item-name
. - --exclude-item-pattern=s
-
Exclude items matching this regex pattern.
- --exclude-item-seq=s@
-
Add item (by sequence number) to exclude list.
Can be specified multiple times.
- --exclude-item-seqs-json=s
-
Exclude items whose sequence number matches this (JSON-encoded).
See
--exclude-item-seq
. - --exclude-item=s@
-
Add item (by name/seq) to exclude list.
Can be specified multiple times.
- --exclude-items-json=s
-
Exclude items whose seq/name matches this (JSON-encoded).
See
--exclude-item
. - --exclude-module-pattern=s
-
Exclude module(s) matching this regex pattern.
- --exclude-module=s@
-
Add module to exclude list.
Can be specified multiple times.
- --exclude-modules-json=s
-
Exclude modules specified in this list (JSON-encoded).
See
--exclude-module
. - --exclude-participant-name=s@
-
Add participant (by name) to exclude list.
Can be specified multiple times.
- --exclude-participant-names-json=s
-
Exclude participants whose name matches this (JSON-encoded).
See
--exclude-participant-name
. - --exclude-participant-pattern=s
-
Exclude participants matching this regex pattern.
- --exclude-participant-seq=s@
-
Add participant (by sequence number) to exclude list.
Can be specified multiple times.
- --exclude-participant-seqs-json=s
-
Exclude participants whose sequence number matches this (JSON-encoded).
See
--exclude-participant-seq
. - --exclude-participant-tag=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.
-
Exclude participants whose tag matches this (JSON-encoded).
See
--exclude-participant-tag
. - --exclude-participant=s@
-
Add participant (by name/seq) to exclude list.
Can be specified multiple times.
- --exclude-participants-json=s
-
Exclude participants whose seq/name matches this (JSON-encoded).
See
--exclude-participant
. - --exclude-perl=s@
-
Add specified perl to exclude list.
Can be specified multiple times.
- --exclude-perls-json=s
-
Exclude some perls (JSON-encoded).
See
--exclude-perl
. - --exclude-pp-modules, --nopp
-
Exclude PP (pure-Perl) modules.
- --exclude-xs-modules, --noxs
-
Exclude XS modules.
- --include-dataset-name=s@
-
Add dataset (by name) to include list.
Can be specified multiple times.
- --include-dataset-names-json=s
-
Only include datasets whose name matches this (JSON-encoded).
See
--include-dataset-name
. - --include-dataset-pattern=s
-
Only include datasets matching this regex pattern.
- --include-dataset-seq=s@
-
Add dataset (by sequence number) to include list.
Can be specified multiple times.
- --include-dataset-seqs-json=s
-
Only include datasets whose sequence number matches this (JSON-encoded).
See
--include-dataset-seq
. - --include-dataset-tag=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.
-
Only include datasets whose tag matches this (JSON-encoded).
See
--include-dataset-tag
. - --include-dataset=s@
-
Add dataset (by name/seq) to include list.
Can be specified multiple times.
- --include-datasets-json=s
-
Only include datasets whose seq/name matches this (JSON-encoded).
See
--include-dataset
. - --include-function-pattern=s
-
Only include functions matching this regex pattern.
- --include-function=s@
-
Add function to include list.
Can be specified multiple times.
- --include-functions-json=s
-
Only include functions specified in this list (JSON-encoded).
See
--include-function
. - --include-item-name=s@
-
Add item (by name) to include list.
Can be specified multiple times.
- --include-item-names-json=s
-
Only include items whose name matches this (JSON-encoded).
See
--include-item-name
. - --include-item-pattern=s
-
Only include items matching this regex pattern.
- --include-item-seq=s@
-
Add item (by sequence number) to include list.
Can be specified multiple times.
- --include-item-seqs-json=s
-
Only include items whose sequence number matches this (JSON-encoded).
See
--include-item-seq
. - --include-item=s@
-
Add item (by name/seq) to include list.
Can be specified multiple times.
- --include-items-json=s
-
Only include items whose seq/name matches this (JSON-encoded).
See
--include-item
. - --include-module-pattern=s
-
Only include modules matching this regex pattern.
- --include-module=s@
-
Add module to include list.
Can be specified multiple times.
- --include-modules-json=s
-
Only include modules specified in this list (JSON-encoded).
See
--include-module
. - --include-participant-name=s@
-
Add participant (by name) to include list.
Can be specified multiple times.
- --include-participant-names-json=s
-
Only include participants whose name matches this (JSON-encoded).
See
--include-participant-name
. - --include-participant-pattern=s
-
Only include participants matching this regex pattern.
- --include-participant-seq=s@
-
Add participant (by sequence number) to include list.
Can be specified multiple times.
- --include-participant-seqs-json=s
-
Only include participants whose sequence number matches this (JSON-encoded).
See
--include-participant-seq
. - --include-participant-tag=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.
-
Only include participants whose tag matches this (JSON-encoded).
See
--include-participant-tag
. - --include-participant=s@
-
Add participant (by name/seq) to include list.
Can be specified multiple times.
- --include-participants-json=s
-
Only include participants whose seq/name matches this (JSON-encoded).
See
--include-participant
. - --include-perl=s@
-
Add specified perl to include list.
Can be specified multiple times.
- --include-perls-json=s
-
Only include some perls (JSON-encoded).
See
--include-perl
.
Logging options
- --debug
-
Shortcut for --log-level=debug.
- --log-level=s
-
Set log level.
By default, these log levels are available (in order of increasing level of importance, from least important to most):
trace
,debug
,info
,warn
/warning
,error
,fatal
. By default, the level is usually set towarn
, which means that log statements with levelinfo
and less important levels will not be shown. To increase verbosity, chooseinfo
,debug
, ortrace
.For more details on log level and logging, as well as how new logging levels can be defined or existing ones modified, see Log::ger.
- --quiet
-
Shortcut for --log-level=error.
- --trace
-
Shortcut for --log-level=trace.
- --verbose
-
Shortcut for --log-level=info.
Multi module version options
- --include-path-json=s, -I
-
Additional module search paths (JSON-encoded).
See
--include-path
. - --include-path=s@
-
Add path to module search path.
Used when searching for scenario module, or when in multimodver mode.
Can be specified multiple times.
- --multimodver=s
-
Benchmark multiple module versions.
If set to a module name, will search for all (instead of the first occurrence) of the module in
@INC
. Then will generate items for each version.Currently only one module can be multi version.
Multiperl options
- --exclude-perl=s@
-
Add specified perl to exclude list.
Can be specified multiple times.
- --exclude-perls-json=s
-
Exclude some perls (JSON-encoded).
See
--exclude-perl
. - --include-perl=s@
-
Add specified perl to include list.
Can be specified multiple times.
- --include-perls-json=s
-
Only include some perls (JSON-encoded).
See
--include-perl
. - --multiperl
-
Benchmark against multiple perls.
Requires App::perlbrew to be installed. Will use installed perls from the perlbrew installation. Each installed perl must have Bencher::Backend module installed (in addition to having all modules that you want to benchmark, obviously).
By default, only perls having Bencher::Backend will be included. Use
--include-perl
and--exclude-perl
to include and exclude which perls you want.Also note that due to the way this is currently implemented, benchmark code that contains closures (references to variables outside the code) won't work.
Output options
- --capture-stderr
-
Trap output to stderr.
- --capture-stdout
-
Trap output to stdout.
- --format=s
-
Choose output format, e.g. json, text.
Default value:
undef
Output can be displayed in multiple formats, and a suitable default format is chosen depending on the application and/or whether output destination is interactive terminal (i.e. whether output is piped). This option specifically chooses an output format.
- --json
-
Set output format to json.
- --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]
- --note=s
-
Put additional note in the result.
- --page-result
-
Filter output through a pager.
This option will pipe the output to a specified pager program. If pager program is not specified, a suitable default e.g.
less
is chosen. - --raw
-
Show "raw" data.
When action=show-items-result, will print result as-is instead of dumping as Perl.
- --render-as-benchmark-pm, -B
-
Format result like Benchmark.pm.
- --result-dir=s
-
Directory to use when saving benchmark result.
Default is from
BENCHER_RESULT_DIR
environment variable, or the home directory. - --result-filename=s
-
Filename to use when saving benchmark result.
Default is:
<NAME>.<yyyy-dd-dd-"T"HH-MM-SS>.json
or, when running in module startup mode:
<NAME>.module_startup.<yyyy-dd-dd-"T"HH-MM-SS>.json
or, when running in code startup mode:
<NAME>.code_startup.<yyyy-dd-dd-"T"HH-MM-SS>.json
where <NAME> is scenario module name, or
NO_MODULE
if scenario is not from a module. The::
(double colon in the module name will be replaced with-
(dash). - --return-meta
-
Whether to return extra metadata.
When set to true, will return extra metadata such as platform information, CPU information, system load before & after the benchmark, system time, and so on. This is put in result metadata under
func.*
keys.The default is to true (return extra metadata) unless when run as CLI and format is text (where the extra metadata is not shown).
- --scientific-notation
-
(No description)
- --sort=s@
-
Default value:
["-time"]
Can be specified multiple times.
- --sorts-json=s
-
See
--sort
. - --view-result
-
View output using a viewer.
This option will first save the output to a temporary file, then open a viewer program to view the temporary file. If a viewer program is not chosen, a suitable default, e.g. the browser, is chosen.
Participant options
- --cpanmodules-module=s
-
Load a scenario from an Acme::CPANModules:: Perl module.
An Acme::CPANModules module can also contain benchmarking information, e.g. Acme::CPANModules::TextTable.
- --participant=s
-
Add a participant.
See
--participants
. - --participants-json=s
-
Add participants (JSON-encoded).
See
--participants
. - --participants=s
-
Add participants.
- --scenario-file=s, -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.
- --scenario-json=s
-
Load a scenario from data structure (JSON-encoded).
See
--scenario
. - --scenario-module=s, -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. - --scenario=s
-
Load a scenario from data structure.
- -p=s
-
Add a participant.
See
--participants
.
Scenario options
- --cpanmodules-module=s
-
Load a scenario from an Acme::CPANModules:: Perl module.
An Acme::CPANModules module can also contain benchmarking information, e.g. Acme::CPANModules::TextTable.
- --scenario-file=s, -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.
- --scenario-json=s
-
Load a scenario from data structure (JSON-encoded).
See
--scenario
. - --scenario-module=s, -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. - --scenario=s
-
Load a scenario from data structure.
Other options
COMPLETION
This script has shell tab completion capability with support for several shells.
bash
To activate bash completion for this script, put:
complete -C bencher bencher
in your bash startup (e.g. ~/.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 modules using cpanm-shcompgen which can activate shell completion for scripts immediately.
tcsh
To activate tcsh completion for this script, put:
complete bencher 'p/*/`bencher`/'
in your tcsh startup (e.g. ~/.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 shcompgen (see above).
other shells
For fish and zsh, install shcompgen as described above.
CONFIGURATION FILE
This script can read configuration files. Configuration files are in the format of IOD, which is basically INI with some extra features.
By default, these names are searched for configuration filenames (can be changed using --config-path
): /home/s1/.config/bencher.conf, /home/s1/bencher.conf, or /etc/bencher.conf.
All found files will be read and merged.
To disable searching for configuration files, pass --no-config
.
You can put multiple profiles in a single file by using section names like [profile=SOMENAME]
or [SOMESECTION profile=SOMENAME]
. Those sections will only be read if you specify the matching --config-profile SOMENAME
.
You can also put configuration for multiple programs inside a single file, and use filter program=NAME
in section names, e.g. [program=NAME ...]
or [SOMESECTION program=NAME]
. The section will then only be used when the reading program matches.
You can also filter a section by environment variable using the filter env=CONDITION
in section names. For example if you only want a section to be read if a certain environment variable is true: [env=SOMEVAR ...]
or [SOMESECTION env=SOMEVAR ...]
. If you only want a section to be read when the value of an environment variable equals some string: [env=HOSTNAME=blink ...]
or [SOMESECTION env=HOSTNAME=blink ...]
. If you only want a section to be read when the value of an environment variable does not equal some string: [env=HOSTNAME!=blink ...]
or [SOMESECTION env=HOSTNAME!=blink ...]
. If you only want a section to be read when the value of an environment variable includes some string: [env=HOSTNAME*=server ...]
or [SOMESECTION env=HOSTNAME*=server ...]
. If you only want a section to be read when the value of an environment variable does not include some string: [env=HOSTNAME!*=server ...]
or [SOMESECTION env=HOSTNAME!*=server ...]
. Note that currently due to simplistic parsing, there must not be any whitespace in the value being compared because it marks the beginning of a new section filter or section name.
To load and configure plugins, you can use either the -plugins
parameter (e.g. -plugins=DumpArgs
or -plugins=DumpArgs@before_validate_args
), or use the [plugin=NAME ...]
sections, for example:
[plugin=DumpArgs]
-event=before_validate_args
-prio=99
[plugin=Foo]
-event=after_validate_args
arg1=val1
arg2=val2
which is equivalent to setting -plugins=-DumpArgs@before_validate_args@99,-Foo@after_validate_args,arg1,val1,arg2,val2
.
List of available configuration parameters:
action (see --action)
capture_stderr (see --capture-stderr)
capture_stdout (see --capture-stdout)
code_startup (see --code-startup)
cpanmodules_module (see --cpanmodules-module)
datasets (see --datasets)
detail (see --detail)
env_hashes (see --env-hashes)
exclude_dataset_names (see --exclude-dataset-name)
exclude_dataset_pattern (see --exclude-dataset-pattern)
exclude_dataset_seqs (see --exclude-dataset-seq)
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_names (see --exclude-item-name)
exclude_item_pattern (see --exclude-item-pattern)
exclude_item_seqs (see --exclude-item-seq)
exclude_items (see --exclude-item)
exclude_module_pattern (see --exclude-module-pattern)
exclude_modules (see --exclude-module)
exclude_participant_names (see --exclude-participant-name)
exclude_participant_pattern (see --exclude-participant-pattern)
exclude_participant_seqs (see --exclude-participant-seq)
exclude_participant_tags (see --exclude-participant-tag)
exclude_participants (see --exclude-participant)
exclude_perls (see --exclude-perl)
exclude_pp_modules (see --exclude-pp-modules)
exclude_xs_modules (see --exclude-xs-modules)
format (see --format)
include_dataset_names (see --include-dataset-name)
include_dataset_pattern (see --include-dataset-pattern)
include_dataset_seqs (see --include-dataset-seq)
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_names (see --include-item-name)
include_item_pattern (see --include-item-pattern)
include_item_seqs (see --include-item-seq)
include_items (see --include-item)
include_module_pattern (see --include-module-pattern)
include_modules (see --include-module)
include_participant_names (see --include-participant-name)
include_participant_pattern (see --include-participant-pattern)
include_participant_seqs (see --include-participant-seq)
include_participant_tags (see --include-participant-tag)
include_participants (see --include-participant)
include_path (see --include-path)
include_perls (see --include-perl)
keep_tempdir (see --keep-tempdir)
log_level (see --log-level)
module_startup (see --module-startup)
multimodver (see --multimodver)
multiperl (see --multiperl)
naked_res (see --naked-res)
note (see --note)
on_failure (see --on-failure)
on_result_failure (see --on-result-failure)
participants (see --participants)
precision (see --precision)
precision_limit (see --precision-limit)
raw (see --raw)
render_as_benchmark_pm (see --render-as-benchmark-pm)
result_dir (see --result-dir)
result_filename (see --result-filename)
return_meta (see --return-meta)
runner (see --runner)
save_result (see --save-result)
scenario (see --scenario)
scenario_file (see --scenario-file)
scenario_module (see --scenario-module)
scientific_notation (see --scientific-notation)
sorts (see --sort)
test (see --test)
tidy (see --tidy)
with_args_size (see --with-args-size)
with_process_size (see --with-process-size)
with_result_size (see --with-result-size)
ENVIRONMENT
BENCHER_OPT
String. Specify additional command-line options.
BENCHER_RESULT_DIR => str
Set default for --results-dir
.
FILES
/home/s1/.config/bencher.conf
/home/s1/bencher.conf
/etc/bencher.conf
HOMEPAGE
Please visit the project's homepage at https://metacpan.org/release/Bencher.
SOURCE
Source repository is at https://github.com/perlancar/perl-Bencher.
SEE ALSO
bencher-tiny if you want a simpler CLI with no non-core dependencies.
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, Pod::Weaver::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond that are considered a bug and can be reported to me.
COPYRIGHT AND LICENSE
This software is copyright (c) 2024 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.
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.