bencher - A benchmark framework (CLI)
This document describes version 1.062.1 of bencher (from Perl distribution Bencher), released on 2022-11-29.
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.
$scenario
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:
-B
% 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).
Bencher::Scenario::*
cpanm -n
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
What datasets are defined?
% bencher -m StringFunctions/Trim --list-datasets empty len10ws1 len100ws1 len100ws10 len100ws100 len1000ws1 len1000ws10 len1000ws100 len1000ws1000
To see the scenario in more detail, let's dump it:
% bencher -m StringFunctions::Trim --dump-parsed-scenario ...
Let's see how the functions will trim the data len100ws10:
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"
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:
::minify
% 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 | +---------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
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 }, ...
% 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
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'
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):
perlbrew list
% 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 ...
For example, if version 0.02 of a module is installed and you want to benchmark against version 0.01 (in /my/home/lib):
/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).
Module::Name
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.
* marks required options.
*
Show detailed information for each result.
Add an environment hash.
See --env-hashes.
--env-hashes
Add environment hashes (JSON-encoded).
Add environment hashes.
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.
What to do when there is a result failure.
["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.
on_failure
There is an extra choice of warn for this type of failure, which is to print a warning to STDERR and continue.
warn
Set precision limit.
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.
precision
precision_limit
default_precision
This setting is useful on slower computers which might not be able to reach the required precision before hitting maximum number of iterations.
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.
$count
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){ ... }).
for(1..100){ ... }
This setting overrides default_precision property in the scenario.
Runner module to use.
["Benchmark::Dumb","Benchmark","Benchmark::Dumb::SimpleTime"]
The default is Benchmark::Dumb which should be good enough for most cases.
Benchmark::Dumb
You can use Benchmark runner (Benchmark.pm) if you are accustomed to it and want to see its output format.
Benchmark
Benchmark.pm
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.
Benchmark::Dumb::SimpleTime
Whether to save benchmark result to file.
Will also be turned on automatically if BENCHER_RESULT_DIR environment variabl is defined.
BENCHER_RESULT_DIR
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 the results_filename option.
results_dir
results_filename
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.
Also return memory usage of item's arguments.
Memory size is measured using Devel::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.
/proc/PID/smaps
Also return memory usage of each item code's result (return value).
Default value:
"bench"
["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"]
Benchmark code startup overhead instead of normal benchmark.
Shortcut for -a dump-items.
See --action.
--action
Shortcut for -a dump-parsed-scenario.
Shortcut for -a list-datasets.
Shortcut for -a list-items.
Shortcut for -a list-participant-modules.
Shortcut for -a list-participants.
Shortcut for -a list-perls.
Shortcut for -a list-permutes.
Shortcut for -a list-scenario-modules.
Benchmark module startup overhead instead of normal benchmark.
Shortcut for -a profile.
Shortcut for -a show-items-codes.
Shortcut for -a show-items-outputs.
Shortcut for -a show-items-results.
Shortcut for -a show-items-results-sizes.
Shortcut for -a show-scenario.
Set path to configuration file.
Can actually be specified multiple times to instruct application to read from multiple configuration files (and merge them).
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 to foo and password to beaver. When you specify --config-profile=production, username will be set to bar and password to honey.
--config-profile=dev
username
foo
password
beaver
--config-profile=production
bar
honey
Do not use any configuration file.
If you specify --no-config, the application will not read any configuration file.
--no-config
Add a dataset.
See --datasets.
--datasets
Add datasets (JSON-encoded).
Add datasets.
Do not cleanup temporary directory when bencher ends.
Run perltidy over generated scripts.
Do not read environment for default options.
If you specify --no-env, the application wil not read any environment variable.
--no-env
Add dataset (by name) to exclude list.
Can be specified multiple times.
Exclude datasets whose name matches this (JSON-encoded).
See --exclude-dataset-name.
--exclude-dataset-name
Exclude datasets matching this regex pattern.
Add dataset (by sequence number) to exclude list.
Exclude datasets whose sequence number matches this (JSON-encoded).
See --exclude-dataset-seq.
--exclude-dataset-seq
Add a tag to dataset exclude tag list.
You can specify A & B to exclude datasets that have both tags A and B.
A & B
Exclude datasets whose tag matches this (JSON-encoded).
See --exclude-dataset-tag.
--exclude-dataset-tag
Add dataset (by name/seq) to exclude list.
Exclude datasets whose seq/name matches this (JSON-encoded).
See --exclude-dataset.
--exclude-dataset
Exclude function(s) matching this regex pattern.
Add function to exclude list.
Exclude functions specified in this list (JSON-encoded).
See --exclude-function.
--exclude-function
Add item (by name) to exclude list.
Exclude items whose name matches this (JSON-encoded).
See --exclude-item-name.
--exclude-item-name
Exclude items matching this regex pattern.
Add item (by sequence number) to exclude list.
Exclude items whose sequence number matches this (JSON-encoded).
See --exclude-item-seq.
--exclude-item-seq
Add item (by name/seq) to exclude list.
Exclude items whose seq/name matches this (JSON-encoded).
See --exclude-item.
--exclude-item
Exclude module(s) matching this regex pattern.
Add module to exclude list.
Exclude modules specified in this list (JSON-encoded).
See --exclude-module.
--exclude-module
Add participant (by name) to exclude list.
Exclude participants whose name matches this (JSON-encoded).
See --exclude-participant-name.
--exclude-participant-name
Exclude participants matching this regex pattern.
Add participant (by sequence number) to exclude list.
Exclude participants whose sequence number matches this (JSON-encoded).
See --exclude-participant-seq.
--exclude-participant-seq
Add a tag to participants exclude tag list.
You can specify A & B to exclude participants that have both tags A and B.
Exclude participants whose tag matches this (JSON-encoded).
See --exclude-participant-tag.
--exclude-participant-tag
Add participant (by name/seq) to exclude list.
Exclude participants whose seq/name matches this (JSON-encoded).
See --exclude-participant.
--exclude-participant
Add specified perl to exclude list.
Exclude some perls (JSON-encoded).
See --exclude-perl.
--exclude-perl
Exclude PP (pure-Perl) modules.
Exclude XS modules.
Add dataset (by name) to include list.
Only include datasets whose name matches this (JSON-encoded).
See --include-dataset-name.
--include-dataset-name
Only include datasets matching this regex pattern.
Add dataset (by sequence number) to include list.
Only include datasets whose sequence number matches this (JSON-encoded).
See --include-dataset-seq.
--include-dataset-seq
Add a tag to dataset include tag list.
You can specify A & B to include datasets that have both tags A and B.
Only include datasets whose tag matches this (JSON-encoded).
See --include-dataset-tag.
--include-dataset-tag
Add dataset (by name/seq) to include list.
Only include datasets whose seq/name matches this (JSON-encoded).
See --include-dataset.
--include-dataset
Only include functions matching this regex pattern.
Add function to include list.
Only include functions specified in this list (JSON-encoded).
See --include-function.
--include-function
Add item (by name) to include list.
Only include items whose name matches this (JSON-encoded).
See --include-item-name.
--include-item-name
Only include items matching this regex pattern.
Add item (by sequence number) to include list.
Only include items whose sequence number matches this (JSON-encoded).
See --include-item-seq.
--include-item-seq
Add item (by name/seq) to include list.
Only include items whose seq/name matches this (JSON-encoded).
See --include-item.
--include-item
Only include modules matching this regex pattern.
Add module to include list.
Only include modules specified in this list (JSON-encoded).
See --include-module.
--include-module
Add participant (by name) to include list.
Only include participants whose name matches this (JSON-encoded).
See --include-participant-name.
--include-participant-name
Only include participants matching this regex pattern.
Add participant (by sequence number) to include list.
Only include participants whose sequence number matches this (JSON-encoded).
See --include-participant-seq.
--include-participant-seq
Add a tag to participants include tag list.
You can specify A & B to include participants that have both tags A and B.
Only include participants whose tag matches this (JSON-encoded).
See --include-participant-tag.
--include-participant-tag
Add participant (by name/seq) to include list.
Only include participants whose seq/name matches this (JSON-encoded).
See --include-participant.
--include-participant
Add specified perl to include list.
Only include some perls (JSON-encoded).
See --include-perl.
--include-perl
Shortcut for --log-level=debug.
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 to warn, which means that log statements with level info and less important levels will not be shown. To increase verbosity, choose info, debug, or trace.
trace
debug
info
warning
error
fatal
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.
Shortcut for --log-level=error.
Shortcut for --log-level=trace.
Shortcut for --log-level=info.
Additional module search paths (JSON-encoded).
See --include-path.
--include-path
Add path to module search path.
Used when searching for scenario module, or when in multimodver mode.
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.
@INC
Currently only one module can be multi version.
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.
Trap output to stderr.
Trap output to stdout.
Choose output format, e.g. json, text.
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.
Set output format to json.
When outputing as JSON, strip result envelope.
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:
--naked-res
[1,2,3]
Put additional note in the 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.
less
Show "raw" data.
When action=show-items-result, will print result as-is instead of dumping as Perl.
Format result like Benchmark.pm.
Directory to use when saving benchmark result.
Default is from BENCHER_RESULT_DIR environment variable, or the home directory.
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).
NO_MODULE
::
-
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.
func.*
The default is to true (return extra metadata) unless when run as CLI and format is text (where the extra metadata is not shown).
(No description)
["-time"]
See --sort.
--sort
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.
Load a scenario from an Acme::CPANModules:: Perl module.
An Acme::CPANModules module can also contain benchmarking information, e.g. Acme::CPANModules::TextTable.
Add a participant.
See --participants.
--participants
Add participants (JSON-encoded).
Add participants.
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.
Load a scenario from data structure (JSON-encoded).
See --scenario.
--scenario
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.
Bencher::Scenario::<NAME>
Load a scenario from data structure.
Display help message and exit.
Display program's version and exit.
This script has shell tab completion capability with support for several shells.
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.
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).
For fish and zsh, install shcompgen as described above.
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/u1/.config/bencher.conf, /home/u1/bencher.conf, or /etc/bencher.conf.
--config-path
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.
[profile=SOMENAME]
[SOMESECTION profile=SOMENAME]
--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.
program=NAME
[program=NAME ...]
[SOMESECTION program=NAME]
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.
env=CONDITION
[env=SOMEVAR ...]
[SOMESECTION env=SOMEVAR ...]
[env=HOSTNAME=blink ...]
[SOMESECTION env=HOSTNAME=blink ...]
[env=HOSTNAME!=blink ...]
[SOMESECTION env=HOSTNAME!=blink ...]
[env=HOSTNAME*=server ...]
[SOMESECTION env=HOSTNAME*=server ...]
[env=HOSTNAME!*=server ...]
[SOMESECTION env=HOSTNAME!*=server ...]
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:
-plugins
-plugins=DumpArgs
-plugins=DumpArgs@before_validate_args
[plugin=NAME ...]
[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.
-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)
String. Specify additional command-line options.
Set default for --results-dir.
--results-dir
Please visit the project's homepage at https://metacpan.org/release/Bencher.
Source repository is at https://github.com/perlancar/perl-Bencher.
bencher-tiny if you want a simpler CLI with no non-core dependencies.
Bencher
Bencher::Backend
Bencher::Manual::*
perlancar <perlancar@cpan.org>
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.
This software is copyright (c) 2022, 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.
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.
To install Bencher, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Bencher
CPAN shell
perl -MCPAN -e shell install Bencher
For more information on module installation, please visit the detailed CPAN module installation guide.