Author image perlancar

NAME

Bencher::Scenario::Accessors::Get - Benchmark attribute read/get

VERSION

This document describes version 0.150 of Bencher::Scenario::Accessors::Get (from Perl distribution Bencher-Scenarios-Accessors), released on 2021-08-03.

SYNOPSIS

To run benchmark with default option:

 % bencher -m Accessors::Get

To run module startup overhead benchmark:

 % bencher --module-startup -m Accessors::Get

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

DESCRIPTION

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.

BENCHMARKED MODULES

Version numbers shown below are the versions used when running the sample benchmark.

Class::Accessor 0.51

Class::Accessor::Array 0.032

Class::Accessor::PackedString 0.001

Class::Accessor::PackedString::Set 0.001

Class::InsideOut 1.14

Class::Struct 0.66

Class::Tiny 1.008

Class::XSAccessor 1.19

Class::XSAccessor::Array 1.19

Mo 0.40

Mojo::Base

Mojo::Base::XS 0.07

Moo 2.004004

Moops 0.038

Moos 0.30

Moose 2.2015

Mouse v2.5.10

Object::Pad 0.46

Object::Simple 3.19

Object::Tiny 1.09

Object::Tiny::RW 1.07

Object::Tiny::RW::XS 0.04

Object::Tiny::XS 1.01

Perl::Examples::Accessors::Array 0.132

Perl::Examples::Accessors::ClassAccessor 0.132

Perl::Examples::Accessors::ClassAccessorArray 0.132

Perl::Examples::Accessors::ClassAccessorPackedString 0.132

Perl::Examples::Accessors::ClassAccessorPackedStringSet 0.132

Perl::Examples::Accessors::ClassInsideOut 0.132

Perl::Examples::Accessors::ClassStruct 0.132

Perl::Examples::Accessors::ClassTiny 0.132

Perl::Examples::Accessors::ClassXSAccessor 0.132

Perl::Examples::Accessors::ClassXSAccessorArray 0.132

Perl::Examples::Accessors::Hash 0.132

Perl::Examples::Accessors::Mo 0.132

Perl::Examples::Accessors::MojoBase 0.132

Perl::Examples::Accessors::MojoBaseXS 0.132

Perl::Examples::Accessors::Moo 0.132

Perl::Examples::Accessors::Moops 0.132

Perl::Examples::Accessors::Moos 0.132

Perl::Examples::Accessors::Moose 0.132

Perl::Examples::Accessors::Mouse 0.132

Perl::Examples::Accessors::ObjectPad 0.132

Perl::Examples::Accessors::ObjectSimple 0.132

Perl::Examples::Accessors::ObjectTiny 0.132

Perl::Examples::Accessors::ObjectTinyRW 0.132

Perl::Examples::Accessors::ObjectTinyRWXS 0.132

Perl::Examples::Accessors::ObjectTinyXS 0.132

Perl::Examples::Accessors::SimpleAccessor 0.132

Simple::Accessor 1.13

BENCHMARK PARTICIPANTS

  • Class::Accessor::PackedString (perl_code)

    Code template:

     state $o = do { my $o = Perl::Examples::Accessors::ClassAccessorPackedString->new; $o->attr1(42); $o }; $o->attr1
  • Class::Accessor::Array (perl_code)

    Code template:

     state $o = do { my $o = Perl::Examples::Accessors::ClassAccessorArray->new; $o->attr1(42); $o }; $o->attr1
  • Mojo::Base (perl_code)

    Code template:

     state $o = do { my $o = Perl::Examples::Accessors::MojoBase->new; $o->attr1(42); $o }; $o->attr1
  • Object::Tiny (perl_code)

    Code template:

     state $o = do { my $o = Perl::Examples::Accessors::ObjectTiny->new(attr1 => 42); $o }; $o->attr1
  • Simple::Accessor (perl_code)

    Code template:

     state $o = do { my $o = Perl::Examples::Accessors::SimpleAccessor->new; $o->attr1(42); $o }; $o->attr1
  • Object::Tiny::RW (perl_code)

    Code template:

     state $o = do { my $o = Perl::Examples::Accessors::ObjectTinyRW->new; $o->attr1(42); $o }; $o->attr1
  • Moose (perl_code)

    Code template:

     state $o = do { my $o = Perl::Examples::Accessors::Moose->new; $o->attr1(42); $o }; $o->attr1
  • Moos (perl_code)

    Code template:

     state $o = do { my $o = Perl::Examples::Accessors::Moos->new; $o->attr1(42); $o }; $o->attr1
  • Object::Pad (perl_code)

    Code template:

     state $o = do { my $o = Perl::Examples::Accessors::ObjectPad->new; $o->set_attr1(42); $o }; $o->attr1
  • Object::Tiny::XS (perl_code)

    Code template:

     state $o = do { my $o = Perl::Examples::Accessors::ObjectTinyXS->new(attr1 => 42); $o }; $o->attr1
  • Mouse (perl_code)

    Code template:

     state $o = do { my $o = Perl::Examples::Accessors::Mouse->new; $o->attr1(42); $o }; $o->attr1
  • Mo (perl_code)

    Code template:

     state $o = do { my $o = Perl::Examples::Accessors::Mo->new; $o->attr1(42); $o }; $o->attr1
  • Object::Simple (perl_code)

    Code template:

     state $o = do { my $o = Perl::Examples::Accessors::ObjectSimple->new; $o->attr1(42); $o }; $o->attr1
  • Moops (perl_code)

    Code template:

     state $o = do { my $o = Perl::Examples::Accessors::Moops->new; $o->attr1(42); $o }; $o->attr1
  • Class::Struct (perl_code)

    Code template:

     state $o = do { my $o = Perl::Examples::Accessors::ClassStruct->new; $o->attr1(42); $o }; $o->attr1
  • Class::XSAccessor (perl_code)

    Code template:

     state $o = do { my $o = Perl::Examples::Accessors::ClassXSAccessor->new; $o->attr1(42); $o }; $o->attr1
  • Object::Tiny::RW::XS (perl_code)

    Code template:

     state $o = do { my $o = Perl::Examples::Accessors::ObjectTinyRWXS->new; $o->attr1(42); $o }; $o->attr1
  • no generator (array-based) (perl_code)

    Code template:

     state $o = do { my $o = Perl::Examples::Accessors::Array->new; $o->attr1(42); $o }; $o->attr1
  • Moo (perl_code)

    Code template:

     state $o = do { my $o = Perl::Examples::Accessors::Moo->new; $o->attr1(42); $o }; $o->attr1
  • Class::InsideOut (perl_code)

    Code template:

     state $o = do { my $o = Perl::Examples::Accessors::ClassInsideOut->new; $o->attr1(42); $o }; $o->attr1
  • Mojo::Base::XS (perl_code)

    Code template:

     state $o = do { my $o = Perl::Examples::Accessors::MojoBaseXS->new; $o->attr1(42); $o }; $o->attr1
  • Class::Accessor (perl_code)

    Code template:

     state $o = do { my $o = Perl::Examples::Accessors::ClassAccessor->new; $o->attr1(42); $o }; $o->attr1
  • Class::Tiny (perl_code)

    Code template:

     state $o = do { my $o = Perl::Examples::Accessors::ClassTiny->new; $o->attr1(42); $o }; $o->attr1
  • no generator (hash-based) (perl_code)

    Code template:

     state $o = do { my $o = Perl::Examples::Accessors::Hash->new; $o->attr1(42); $o }; $o->attr1
  • Class::Accessor::PackedString::Set (perl_code)

    Code template:

     state $o = do { my $o = Perl::Examples::Accessors::ClassAccessorPackedStringSet->new; $o->attr1(42); $o }; $o->attr1
  • Class::XSAccessor::Array (perl_code)

    Code template:

     state $o = do { my $o = Perl::Examples::Accessors::ClassXSAccessorArray->new; $o->attr1(42); $o }; $o->attr1
  • raw hash access (perl_code)

    Code template:

     state $o = do { my $o = Perl::Examples::Accessors::Hash->new; $o->attr1(42); $o }; $o->{attr1}
  • raw array access (perl_code)

    Code template:

     state $o = do { my $o = Perl::Examples::Accessors::Array->new; $o->attr1(42); $o }; $o->[0]

BENCHMARK SAMPLE RESULTS

Sample benchmark #1

Run on: perl: v5.34.0, CPU: Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz (4 cores), OS: GNU/Linux LinuxMint version 19, OS kernel: Linux version 5.3.0-68-generic.

Benchmark command (default options):

 % bencher -m Accessors::Get

Result formatted as table:

 #table1#
 +------------------------------------+------------+-----------+-----------------------+-----------------------+---------+---------+
 | participant                        |  rate (/s) | time (ns) | pct_faster_vs_slowest | pct_slower_vs_fastest |  errors | samples |
 +------------------------------------+------------+-----------+-----------------------+-----------------------+---------+---------+
 | Class::Accessor::PackedString::Set |    2000000 |       600 |                 0.00% |            -10483.94% | 1.6e-08 |      21 |
 | Class::Accessor::Array             |    2200000 |       460 |                23.99% |             -8475.01% | 2.3e-09 |      20 |
 | Object::Pad                        |    2000000 |       400 |                37.22% |             -7667.54% | 5.2e-09 |      20 |
 | Class::Accessor::PackedString      |    2000000 |       400 |                38.66% |             -7588.70% | 1.7e-08 |      20 |
 | Class::Accessor                    |    3000000 |       400 |                44.98% |             -7262.48% | 2.1e-08 |      20 |
 | Class::InsideOut                   |    3000000 |       400 |                61.32% |             -6536.79% | 6.9e-09 |      21 |
 | Mo                                 |    3000000 |       300 |                80.30% |             -5859.41% | 1.3e-08 |      20 |
 | Mojo::Base                         |    4000000 |       200 |               137.49% |             -4472.46% | 1.2e-08 |      20 |
 | Simple::Accessor                   |    4000000 |       200 |               139.63% |             -4433.24% | 5.7e-09 |      20 |
 | Class::Tiny                        |    5000000 |       200 |               166.06% |             -4002.89% | 1.2e-08 |      21 |
 | no generator (hash-based)          |    5000000 |       200 |               203.33% |             -3523.27% | 3.6e-09 |      21 |
 | no generator (array-based)         |    6000000 |       200 |               231.72% |             -3230.31% | 4.1e-09 |      20 |
 | Class::Struct                      |    6000000 |       170 |               242.10% |             -3135.35% |   1e-09 |      20 |
 | Object::Simple                     |    6000000 |       200 |               264.60% |             -2948.05% | 3.7e-09 |      20 |
 | Object::Tiny::RW                   |    7000000 |       100 |               322.42% |             -2558.21% | 3.6e-09 |      20 |
 | Moose                              |    8000000 |       100 |               327.94% |             -2526.49% | 4.3e-09 |      20 |
 | Object::Tiny::XS                   |    8000000 |       100 |               335.23% |             -2485.84% | 1.7e-09 |      20 |
 | Mojo::Base::XS                     |    9000000 |       100 |               391.55% |             -2212.50% | 5.9e-09 |      28 |
 | Moops                              |    9000000 |       100 |               403.91% |             -2160.65% | 7.9e-09 |      20 |
 | Moos                               |   10000000 |       100 |               475.19% |             -1905.31% | 6.7e-09 |      35 |
 | raw hash access                    |   10000000 |        90 |               501.10% |             -1827.49% | 2.2e-09 |      22 |
 | Object::Tiny                       |   11000000 |        94 |               505.39% |             -1815.25% | 8.7e-10 |      20 |
 | Mouse                              |   12000000 |        81 |               600.65% |             -1582.04% | 4.8e-10 |      20 |
 | Moo                                |   16000000 |        63 |               807.87% |             -1243.77% |   3e-10 |      20 |
 | Object::Tiny::RW::XS               |   20000000 |        60 |               848.65% |             -1194.60% | 1.3e-09 |      20 |
 | Class::XSAccessor                  |   20000000 |        40 |              1277.21% |              -853.98% | 1.9e-09 |      22 |
 | Class::XSAccessor::Array           |   40000000 |        20 |              2411.56% |              -513.45% | 1.5e-09 |      20 |
 | raw array access                   | -200000000 |        -5 |            -10483.94% |                 0.00% | 2.2e-10 |      20 |
 +------------------------------------+------------+-----------+-----------------------+-----------------------+---------+---------+

The above result formatted in Benchmark.pm style:

                                              Rate  Class::Accessor::PackedString::Set  Class::Accessor::Array  Object::Pad  Class::Accessor::PackedString  Class::Accessor  Class::InsideOut      Mo  Mojo::Base  Simple::Accessor  Class::Tiny  no generator (hash-based)  no generator (array-based)  Object::Simple  Class::Struct  Object::Tiny::RW   Moose  Object::Tiny::XS  Mojo::Base::XS   Moops    Moos  Object::Tiny  raw hash access   Mouse     Moo  Object::Tiny::RW::XS  Class::XSAccessor  Class::XSAccessor::Array  raw array access 
  Class::Accessor::PackedString::Set     2000000/s                                  --                    -23%         -33%                           -33%             -33%              -33%    -50%        -66%              -66%         -66%                       -66%                        -66%            -66%           -71%              -83%    -83%              -83%            -83%    -83%    -83%          -84%             -85%    -86%    -89%                  -90%               -93%                      -96%             -100% 
  Class::Accessor::Array                 2200000/s                                 30%                      --         -13%                           -13%             -13%              -13%    -34%        -56%              -56%         -56%                       -56%                        -56%            -56%           -63%              -78%    -78%              -78%            -78%    -78%    -78%          -79%             -80%    -82%    -86%                  -86%               -91%                      -95%             -101% 
  Object::Pad                            2000000/s                                 50%                     14%           --                             0%               0%                0%    -25%        -50%              -50%         -50%                       -50%                        -50%            -50%           -57%              -75%    -75%              -75%            -75%    -75%    -75%          -76%             -77%    -79%    -84%                  -85%               -90%                      -95%             -101% 
  Class::Accessor::PackedString          2000000/s                                 50%                     14%           0%                             --               0%                0%    -25%        -50%              -50%         -50%                       -50%                        -50%            -50%           -57%              -75%    -75%              -75%            -75%    -75%    -75%          -76%             -77%    -79%    -84%                  -85%               -90%                      -95%             -101% 
  Class::Accessor                        3000000/s                                 50%                     14%           0%                             0%               --                0%    -25%        -50%              -50%         -50%                       -50%                        -50%            -50%           -57%              -75%    -75%              -75%            -75%    -75%    -75%          -76%             -77%    -79%    -84%                  -85%               -90%                      -95%             -101% 
  Class::InsideOut                       3000000/s                                 50%                     14%           0%                             0%               0%                --    -25%        -50%              -50%         -50%                       -50%                        -50%            -50%           -57%              -75%    -75%              -75%            -75%    -75%    -75%          -76%             -77%    -79%    -84%                  -85%               -90%                      -95%             -101% 
  Mo                                     3000000/s                                100%                     53%          33%                            33%              33%               33%      --        -33%              -33%         -33%                       -33%                        -33%            -33%           -43%              -66%    -66%              -66%            -66%    -66%    -66%          -68%             -70%    -73%    -79%                  -80%               -86%                      -93%             -101% 
  Mojo::Base                             4000000/s                                200%                    129%         100%                           100%             100%              100%     50%          --                0%           0%                         0%                          0%              0%           -15%              -50%    -50%              -50%            -50%    -50%    -50%          -53%             -55%    -59%    -68%                  -70%               -80%                      -90%             -102% 
  Simple::Accessor                       4000000/s                                200%                    129%         100%                           100%             100%              100%     50%          0%                --           0%                         0%                          0%              0%           -15%              -50%    -50%              -50%            -50%    -50%    -50%          -53%             -55%    -59%    -68%                  -70%               -80%                      -90%             -102% 
  Class::Tiny                            5000000/s                                200%                    129%         100%                           100%             100%              100%     50%          0%                0%           --                         0%                          0%              0%           -15%              -50%    -50%              -50%            -50%    -50%    -50%          -53%             -55%    -59%    -68%                  -70%               -80%                      -90%             -102% 
  no generator (hash-based)              5000000/s                                200%                    129%         100%                           100%             100%              100%     50%          0%                0%           0%                         --                          0%              0%           -15%              -50%    -50%              -50%            -50%    -50%    -50%          -53%             -55%    -59%    -68%                  -70%               -80%                      -90%             -102% 
  no generator (array-based)             6000000/s                                200%                    129%         100%                           100%             100%              100%     50%          0%                0%           0%                         0%                          --              0%           -15%              -50%    -50%              -50%            -50%    -50%    -50%          -53%             -55%    -59%    -68%                  -70%               -80%                      -90%             -102% 
  Object::Simple                         6000000/s                                200%                    129%         100%                           100%             100%              100%     50%          0%                0%           0%                         0%                          0%              --           -15%              -50%    -50%              -50%            -50%    -50%    -50%          -53%             -55%    -59%    -68%                  -70%               -80%                      -90%             -102% 
  Class::Struct                          6000000/s                                252%                    170%         135%                           135%             135%              135%     76%         17%               17%          17%                        17%                         17%             17%             --              -41%    -41%              -41%            -41%    -41%    -41%          -44%             -47%    -52%    -62%                  -64%               -76%                      -88%             -102% 
  Object::Tiny::RW                       7000000/s                                500%                    359%         300%                           300%             300%              300%    200%        100%              100%         100%                       100%                        100%            100%            70%                --      0%                0%              0%      0%      0%           -6%              -9%    -18%    -37%                  -40%               -60%                      -80%             -105% 
  Moose                                  8000000/s                                500%                    359%         300%                           300%             300%              300%    200%        100%              100%         100%                       100%                        100%            100%            70%                0%      --                0%              0%      0%      0%           -6%              -9%    -18%    -37%                  -40%               -60%                      -80%             -105% 
  Object::Tiny::XS                       8000000/s                                500%                    359%         300%                           300%             300%              300%    200%        100%              100%         100%                       100%                        100%            100%            70%                0%      0%                --              0%      0%      0%           -6%              -9%    -18%    -37%                  -40%               -60%                      -80%             -105% 
  Mojo::Base::XS                         9000000/s                                500%                    359%         300%                           300%             300%              300%    200%        100%              100%         100%                       100%                        100%            100%            70%                0%      0%                0%              --      0%      0%           -6%              -9%    -18%    -37%                  -40%               -60%                      -80%             -105% 
  Moops                                  9000000/s                                500%                    359%         300%                           300%             300%              300%    200%        100%              100%         100%                       100%                        100%            100%            70%                0%      0%                0%              0%      --      0%           -6%              -9%    -18%    -37%                  -40%               -60%                      -80%             -105% 
  Moos                                  10000000/s                                500%                    359%         300%                           300%             300%              300%    200%        100%              100%         100%                       100%                        100%            100%            70%                0%      0%                0%              0%      0%      --           -6%              -9%    -18%    -37%                  -40%               -60%                      -80%             -105% 
  Object::Tiny                          11000000/s                                538%                    389%         325%                           325%             325%              325%    219%        112%              112%         112%                       112%                        112%            112%            80%                6%      6%                6%              6%      6%      6%            --              -4%    -13%    -32%                  -36%               -57%                      -78%             -105% 
  raw hash access                       10000000/s                                566%                    411%         344%                           344%             344%              344%    233%        122%              122%         122%                       122%                        122%            122%            88%               11%     11%               11%             11%     11%     11%            4%               --     -9%    -30%                  -33%               -55%                      -77%             -105% 
  Mouse                                 12000000/s                                640%                    467%         393%                           393%             393%              393%    270%        146%              146%         146%                       146%                        146%            146%           109%               23%     23%               23%             23%     23%     23%           16%              11%      --    -22%                  -25%               -50%                      -75%             -106% 
  Moo                                   16000000/s                                852%                    630%         534%                           534%             534%              534%    376%        217%              217%         217%                       217%                        217%            217%           169%               58%     58%               58%             58%     58%     58%           49%              42%     28%      --                   -4%               -36%                      -68%             -107% 
  Object::Tiny::RW::XS                  20000000/s                                900%                    666%         566%                           566%             566%              566%    400%        233%              233%         233%                       233%                        233%            233%           183%               66%     66%               66%             66%     66%     66%           56%              50%     35%      5%                    --               -33%                      -66%             -108% 
  Class::XSAccessor                     20000000/s                               1400%                   1050%         900%                           900%             900%              900%    650%        400%              400%         400%                       400%                        400%            400%           325%              150%    150%              150%            150%    150%    150%          135%             125%    102%     57%                   50%                 --                      -50%             -112% 
  Class::XSAccessor::Array              40000000/s                               2900%                   2200%        1900%                          1900%            1900%             1900%   1400%        900%              900%         900%                       900%                        900%            900%           750%              400%    400%              400%            400%    400%    400%          370%             350%    305%    215%                  200%               100%                        --             -125% 
  raw array access                    -200000000/s                             -12100%                  -9300%       -8100%                         -8100%           -8100%            -8100%  -6100%      -4100%            -4100%       -4100%                     -4100%                      -4100%          -4100%         -3500%            -2100%  -2100%            -2100%          -2100%  -2100%  -2100%        -1980%           -1900%  -1720%  -1360%                -1300%              -900%                     -500%                -- 
 
 Legends:
   Class::Accessor: participant=Class::Accessor
   Class::Accessor::Array: participant=Class::Accessor::Array
   Class::Accessor::PackedString: participant=Class::Accessor::PackedString
   Class::Accessor::PackedString::Set: participant=Class::Accessor::PackedString::Set
   Class::InsideOut: participant=Class::InsideOut
   Class::Struct: participant=Class::Struct
   Class::Tiny: participant=Class::Tiny
   Class::XSAccessor: participant=Class::XSAccessor
   Class::XSAccessor::Array: participant=Class::XSAccessor::Array
   Mo: participant=Mo
   Mojo::Base: participant=Mojo::Base
   Mojo::Base::XS: participant=Mojo::Base::XS
   Moo: participant=Moo
   Moops: participant=Moops
   Moos: participant=Moos
   Moose: participant=Moose
   Mouse: participant=Mouse
   Object::Pad: participant=Object::Pad
   Object::Simple: participant=Object::Simple
   Object::Tiny: participant=Object::Tiny
   Object::Tiny::RW: participant=Object::Tiny::RW
   Object::Tiny::RW::XS: participant=Object::Tiny::RW::XS
   Object::Tiny::XS: participant=Object::Tiny::XS
   Simple::Accessor: participant=Simple::Accessor
   no generator (array-based): participant=no generator (array-based)
   no generator (hash-based): participant=no generator (hash-based)
   raw array access: participant=raw array access
   raw hash access: participant=raw hash access

The above result presented as chart:

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-Accessors.

SOURCE

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

BUGS

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

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

SEE ALSO

AUTHOR

perlancar <perlancar@cpan.org>

COPYRIGHT AND LICENSE

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