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

NAME

Bencher::Scenario::PERLANCAR::state - Benchmark overhead of state (vs my) variables in a tight subroutine

VERSION

This document describes version 0.06 of Bencher::Scenario::PERLANCAR::state (from Perl distribution Bencher-Scenarios-PERLANCAR), released on 2017-01-25.

SYNOPSIS

To run benchmark with default option:

 % bencher -m PERLANCAR::state

For more options (dump scenario, list/include/exclude/add participants, list/include/exclude/add datasets, etc), see bencher or run bencher --help.

DESCRIPTION

Each variable declaration is not free.

Packaging a benchmark script as a Bencher scenario makes it convenient to include/exclude/add participants/datasets (either via CLI or Perl code), send the result to a central repository, among others . See Bencher and bencher (CLI) for more details.

BENCHMARK PARTICIPANTS

  • baseline_0 (perl_code)

    Code template:

  • 1_state (perl_code)

    Code template:

     state $s1 = 1
  • 2_state (perl_code)

    Code template:

     state $s1 = 1; state $s2 = 1
  • 5_state (perl_code)

    Code template:

     state $s1 = 1; state $s2 = 1; state $s3 = 1; state $s4 = 1; state $s5 = 1; 
  • 10_state (perl_code)

    Code template:

     state $s1=1; state $s2=1; state $s3=1; state $s4=1; state $s5=1; state $s6=1; state $s7=1; state $s8=1; state $s9=1; state $s10=1; 
  • 5_state_do (perl_code) (not included by default)

    Code template:

     my $s1 = 1
  • 1_my (perl_code)

    Code template:

     my $s1 = 1; my $s2 = 1
  • 2_my (perl_code)

    Code template:

     my $s1 = 1; my $s2 = 1; my $s3 = 1; my $s4 = 1; my $s5 = 1; 
  • 5_my (perl_code)

    Code template:

     my $s1=1; my $s2=1; my $s3=1; my $s4=1; my $s5=1; my $s6=1; my $s7=1; my $s8=1; my $s9=1; my $s10=1; 
  • 10_my (perl_code)

SAMPLE BENCHMARK RESULTS

Run on: perl: v5.24.0, CPU: Intel(R) Core(TM) M-5Y71 CPU @ 1.20GHz (2 cores), OS: GNU/Linux LinuxMint version 17.3, OS kernel: Linux version 3.19.0-32-generic.

Benchmark with default options (bencher -m PERLANCAR::state):

 #table1#
 +-------------+-----------+-----------+------------+---------+---------+
 | participant | rate (/s) | time (ns) | vs_slowest |  errors | samples |
 +-------------+-----------+-----------+------------+---------+---------+
 | 10_my       |   3400000 |     290   |       1    | 4.2e-10 |      20 |
 | 10_state    |   6900000 |     150   |       2    | 3.7e-10 |      25 |
 | 5_my        |   7100000 |     141   |       2.08 |   1e-10 |      20 |
 | 5_state     |  11700000 |      85.7 |       3.42 | 5.2e-11 |      20 |
 | 2_my        |  16000000 |      61   |       4.8  | 2.4e-10 |      27 |
 | 1_my        |  36500000 |      27.4 |      10.7  | 2.6e-11 |      20 |
 | 2_state     |  47000000 |      21   |      14    | 5.3e-11 |      20 |
 | 1_state     | 100000000 |      10   |      30    | 2.4e-10 |      28 |
 | baseline_0  | 600000000 |       2   |     200    | 2.1e-10 |      20 |
 +-------------+-----------+-----------+------------+---------+---------+

To display as an interactive HTML table on a browser, you can add option --format html+datatables.

HOMEPAGE

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

SOURCE

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

BUGS

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Bencher-Scenarios-PERLANCAR

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.

AUTHOR

perlancar <perlancar@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2017 by 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.