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

NAME

bench.pl - Compare the performance of perl code snippets across multiple perls.

SYNOPSIS

    # Basic: run the tests in t/perf/benchmarks against two or
    # more perls

    bench.pl [options] perl1[=label1] perl2[=label2] ...

    # Run bench.pl's own built-in sanity tests

    bench.pl --action=selftest

DESCRIPTION

By default, bench.pl will run code snippets found in t/perf/benchmarks (or similar) under cachegrind, in order to calculate how many instruction reads, data writes, branches, cache misses, etc. that one execution of the snippet uses. It will run them against two or more perl executables and show how much each test has gotten better or worse.

It is modelled on the perlbench tool, but since it measures instruction reads etc., rather than timings, it is much more precise and reproducible. It is also considerably faster, and is capable or running tests in parallel (with -j). Rather than displaying a single relative percentage per test/perl combination, it displays values for 13 different measurements, such as instruction reads, conditional branch misses etc.

There are options to write the raw data to a file, and to read it back. This means that you can view the same run data in different views with different selection and sort options.

The optional =label after each perl executable is used in the display output.

OPTIONS

  • --action=foo

    What action to perform. The default is grind, which runs the benchmarks using cachegrind as the back end. The only other action at the moment is selftest, which runs some basic sanity checks and produces TAP output.

  • --average

    Only display the overall average, rather than the results for each individual test.

  • --benchfile=foo

    The path of the file which contains the benchmarks (t/perf/benchmarks by default).

  • --bisect=field,minval,maxval

    Run a single test against one perl and exit with a zero status if the named field is in the specified range; exit 1 otherwise. It will complain if more than one test or perl has been specified. It is intended to be called as part of a bisect run, to determine when something changed. For example,

        bench.pl -j 8 --tests=foo --bisect=Ir,100,105 --perlargs=-Ilib \
            ./miniperl

    might be called from bisect to find when the number of instruction reads for test foo falls outside the range 100..105.

  • --debug

    Enable verbose debugging output.

  • --fields=a,b,c

    Display only the specified fields; for example,

        --fields=Ir,Ir_m,Ir_mm

    If only one field is selected, the output is in more compact form.

  • --grindargs=foo

    Optional command-line arguments to pass to cachegrind invocations.

  • ---help

    Display basic usage information.

  • -j N --jobs=N

    Run N jobs in parallel (default 1). This determines how many cachegrind process will running at a time, and should generally be set to the number of CPUs available.

  • --norm=foo

    Specify which perl column in the output to treat as the 100% norm. It may be a column number (0..N-1) or a perl executable name or label. It defaults to the leftmost column.

  • --perlargs=foo

    Optional command-line arguments to pass to each perl that is run as part of a cachegrind session. For example, --perlargs=-Ilib.

  • --raw

    Display raw data counts rather than percentages in the outputs. This allows you to see the exact number of intruction reads, branch misses etc. for each test/perl combination. It also causes the AVERAGE display per field to be calculated based on the average of each tests's count rather than average of each percentage. This means that tests with very high counts will dominate.

  • --sort=field:perl

    Order the tests in the output based on the value of field in the column perl. The perl value is as per --norm. For example

        bench.pl --sort=Dw:perl-5.20.0 \
            perl-5.16.0 perl-5.18.0 perl-5.20.0
  • -r file --read=file

    Read in saved data from a previous --write run from the specified file.

    Requires JSON::PP to be available.

  • --tests=FOO

    Specify a subset of tests to run (or in the case of --read, to display). It may be either a comma-separated list of test names, or a regular expression. For example

        --tests=expr::assign::scalar_lex,expr::assign::2list_lex
        --tests=/^expr::/
  • --verbose

    Display progress information.

  • -w file --write=file

    Save the raw data to the specified file. It can be read back later with --read.

    Requires JSON::PP to be available.