NAME

Bencher::Scenario::Accessors::Set - Benchmark attribute write/set

VERSION

This document describes version 0.151 of Bencher::Scenario::Accessors::Set (from Perl distribution Bencher-ScenarioBundle-Accessors), released on 2024-05-06.

SYNOPSIS

To run benchmark with default option:

% bencher -m Accessors::Set

To run module startup overhead benchmark:

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

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

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

Moops 0.038

Moos 0.30

Moose 2.2206

Mouse v2.5.10

Object::Pad 0.806

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::ObjectTinyRW 0.132

Perl::Examples::Accessors::ObjectTinyRWXS 0.132

Perl::Examples::Accessors::SimpleAccessor 0.132

Simple::Accessor 1.13

BENCHMARK PARTICIPANTS

  • Class::Tiny (perl_code)

    Code template:

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

    Code template:

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

    Code template:

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

    Code template:

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

    Code template:

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

    Code template:

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

    Code template:

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

    Code template:

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

    Code template:

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

    Code template:

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

    Code template:

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

    Code template:

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

    Code template:

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

    Code template:

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

    Code template:

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

    Code template:

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

    Code template:

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

    Code template:

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

    Code template:

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

    Code template:

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

    Code template:

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

    Code template:

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

    Code template:

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

    Code template:

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

    Code template:

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

    Code template:

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

BENCHMARK SAMPLE RESULTS

Sample benchmark #1

Run on: perl: v5.38.2, 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-164-generic.

Benchmark command (default options):

% bencher -m Accessors::Set

Result formatted as table:

#table1#
+------------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
| participant                        | rate (/s) | time (ns) | pct_faster_vs_slowest | pct_slower_vs_fastest |  errors | samples |
+------------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
| Simple::Accessor                   |    718000 |    1390   |                 0.00% |              2838.97% | 4.5e-10 |      20 |
| Class::Accessor::PackedString::Set |   1430000 |     699   |                99.12% |              1375.97% | 3.3e-10 |      20 |
| Class::Accessor::PackedString      |   1950000 |     514   |               170.83% |               985.18% | 2.9e-10 |      21 |
| Class::Accessor                    |   2080000 |     480.8 |               189.62% |               914.78% |   4e-11 |      22 |
| Class::InsideOut                   |   2680000 |     372   |               273.84% |               686.16% | 1.3e-10 |      22 |
| Object::Pad                        |   3830000 |     261   |               432.63% |               451.78% | 1.4e-10 |      20 |
| Moose                              |   4040000 |     248   |               462.21% |               422.76% | 5.6e-11 |      24 |
| Object::Tiny::RW                   |   4100000 |     250   |               465.92% |               419.33% | 4.8e-10 |      20 |
| Class::Struct                      |   4430000 |     226   |               516.87% |               376.43% | 7.8e-11 |      20 |
| Class::Accessor::Array             |   4640000 |     216   |               545.38% |               355.39% | 6.2e-11 |      22 |
| Mojo::Base                         |   4910000 |     204   |               584.01% |               329.67% | 1.1e-10 |      21 |
| Object::Simple                     |   5150000 |     194   |               616.89% |               309.96% | 9.1e-11 |      20 |
| no generator (hash-based)          |   5280000 |     189   |               635.52% |               299.57% | 1.1e-10 |      20 |
| Class::Tiny                        |   5360000 |     186   |               646.95% |               293.47% | 8.7e-11 |      21 |
| Mo                                 |   5370000 |     186   |               647.38% |               293.23% | 1.4e-10 |      24 |
| no generator (array-based)         |   5980000 |     167   |               732.60% |               252.99% | 1.1e-10 |      20 |
| Mouse                              |   9210000 |     109   |              1181.81% |               129.28% | 3.6e-11 |      21 |
| Object::Tiny::RW::XS               |  11000000 |      94   |              1375.12% |                99.24% | 1.9e-10 |      20 |
| Moos                               |  10700000 |      93.8 |              1384.43% |                97.99% |   8e-11 |      20 |
| Moops                              |  11100000 |      90.4 |              1439.42% |                90.91% | 4.9e-11 |      20 |
| Class::XSAccessor                  |  11000000 |      88   |              1473.83% |                86.74% |   9e-11 |      20 |
| Mojo::Base::XS                     |  11300000 |      88.4 |              1474.96% |                86.61% | 7.8e-11 |      20 |
| Moo                                |  11000000 |      88   |              1485.57% |                85.36% |   1e-10 |      24 |
| Class::XSAccessor::Array           |  13000000 |      75   |              1763.55% |                57.71% | 1.3e-10 |      20 |
| raw hash access                    |  17000000 |      60   |              2229.43% |                26.17% | 7.4e-11 |      21 |
| raw array access                   |  21000000 |      47   |              2838.97% |                 0.00% | 1.5e-10 |      20 |
+------------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+

The above result formatted in Benchmark.pm style:

                                           Rate  Simple::Accessor  Class::Accessor::PackedString::Set  Class::Accessor::PackedString  Class::Accessor  Class::InsideOut  Object::Pad  Object::Tiny::RW  Moose  Class::Struct  Class::Accessor::Array  Mojo::Base  Object::Simple  no generator (hash-based)  Class::Tiny    Mo  no generator (array-based)  Mouse  Object::Tiny::RW::XS  Moos  Moops  Mojo::Base::XS  Class::XSAccessor   Moo  Class::XSAccessor::Array  raw hash access  raw array access 
 Simple::Accessor                      718000/s                --                                -49%                           -63%             -65%              -73%         -81%              -82%   -82%           -83%                    -84%        -85%            -86%                       -86%         -86%  -86%                        -87%   -92%                  -93%  -93%   -93%            -93%               -93%  -93%                      -94%             -95%              -96% 
 Class::Accessor::PackedString::Set   1430000/s               98%                                  --                           -26%             -31%              -46%         -62%              -64%   -64%           -67%                    -69%        -70%            -72%                       -72%         -73%  -73%                        -76%   -84%                  -86%  -86%   -87%            -87%               -87%  -87%                      -89%             -91%              -93% 
 Class::Accessor::PackedString        1950000/s              170%                                 35%                             --              -6%              -27%         -49%              -51%   -51%           -56%                    -57%        -60%            -62%                       -63%         -63%  -63%                        -67%   -78%                  -81%  -81%   -82%            -82%               -82%  -82%                      -85%             -88%              -90% 
 Class::Accessor                      2080000/s              189%                                 45%                             6%               --              -22%         -45%              -48%   -48%           -52%                    -55%        -57%            -59%                       -60%         -61%  -61%                        -65%   -77%                  -80%  -80%   -81%            -81%               -81%  -81%                      -84%             -87%              -90% 
 Class::InsideOut                     2680000/s              273%                                 87%                            38%              29%                --         -29%              -32%   -33%           -39%                    -41%        -45%            -47%                       -49%         -50%  -50%                        -55%   -70%                  -74%  -74%   -75%            -76%               -76%  -76%                      -79%             -83%              -87% 
 Object::Pad                          3830000/s              432%                                167%                            96%              84%               42%           --               -4%    -4%           -13%                    -17%        -21%            -25%                       -27%         -28%  -28%                        -36%   -58%                  -63%  -64%   -65%            -66%               -66%  -66%                      -71%             -77%              -81% 
 Object::Tiny::RW                     4100000/s              455%                                179%                           105%              92%               48%           4%                --     0%            -9%                    -13%        -18%            -22%                       -24%         -25%  -25%                        -33%   -56%                  -62%  -62%   -63%            -64%               -64%  -64%                      -70%             -76%              -81% 
 Moose                                4040000/s              460%                                181%                           107%              93%               50%           5%                0%     --            -8%                    -12%        -17%            -21%                       -23%         -25%  -25%                        -32%   -56%                  -62%  -62%   -63%            -64%               -64%  -64%                      -69%             -75%              -81% 
 Class::Struct                        4430000/s              515%                                209%                           127%             112%               64%          15%               10%     9%             --                     -4%         -9%            -14%                       -16%         -17%  -17%                        -26%   -51%                  -58%  -58%   -60%            -60%               -61%  -61%                      -66%             -73%              -79% 
 Class::Accessor::Array               4640000/s              543%                                223%                           137%             122%               72%          20%               15%    14%             4%                      --         -5%            -10%                       -12%         -13%  -13%                        -22%   -49%                  -56%  -56%   -58%            -59%               -59%  -59%                      -65%             -72%              -78% 
 Mojo::Base                           4910000/s              581%                                242%                           151%             135%               82%          27%               22%    21%            10%                      5%          --             -4%                        -7%          -8%   -8%                        -18%   -46%                  -53%  -54%   -55%            -56%               -56%  -56%                      -63%             -70%              -76% 
 Object::Simple                       5150000/s              616%                                260%                           164%             147%               91%          34%               28%    27%            16%                     11%          5%              --                        -2%          -4%   -4%                        -13%   -43%                  -51%  -51%   -53%            -54%               -54%  -54%                      -61%             -69%              -75% 
 no generator (hash-based)            5280000/s              635%                                269%                           171%             154%               96%          38%               32%    31%            19%                     14%          7%              2%                         --          -1%   -1%                        -11%   -42%                  -50%  -50%   -52%            -53%               -53%  -53%                      -60%             -68%              -75% 
 Class::Tiny                          5360000/s              647%                                275%                           176%             158%              100%          40%               34%    33%            21%                     16%          9%              4%                         1%           --    0%                        -10%   -41%                  -49%  -49%   -51%            -52%               -52%  -52%                      -59%             -67%              -74% 
 Mo                                   5370000/s              647%                                275%                           176%             158%              100%          40%               34%    33%            21%                     16%          9%              4%                         1%           0%    --                        -10%   -41%                  -49%  -49%   -51%            -52%               -52%  -52%                      -59%             -67%              -74% 
 no generator (array-based)           5980000/s              732%                                318%                           207%             187%              122%          56%               49%    48%            35%                     29%         22%             16%                        13%          11%   11%                          --   -34%                  -43%  -43%   -45%            -47%               -47%  -47%                      -55%             -64%              -71% 
 Mouse                                9210000/s             1175%                                541%                           371%             341%              241%         139%              129%   127%           107%                     98%         87%             77%                        73%          70%   70%                         53%     --                  -13%  -13%   -17%            -18%               -19%  -19%                      -31%             -44%              -56% 
 Object::Tiny::RW::XS                11000000/s             1378%                                643%                           446%             411%              295%         177%              165%   163%           140%                    129%        117%            106%                       101%          97%   97%                         77%    15%                    --    0%    -3%             -5%                -6%   -6%                      -20%             -36%              -50% 
 Moos                                10700000/s             1381%                                645%                           447%             412%              296%         178%              166%   164%           140%                    130%        117%            106%                       101%          98%   98%                         78%    16%                    0%    --    -3%             -5%                -6%   -6%                      -20%             -36%              -49% 
 Moops                               11100000/s             1437%                                673%                           468%             431%              311%         188%              176%   174%           150%                    138%        125%            114%                       109%         105%  105%                         84%    20%                    3%    3%     --             -2%                -2%   -2%                      -17%             -33%              -48% 
 Mojo::Base::XS                      11300000/s             1472%                                690%                           481%             443%              320%         195%              182%   180%           155%                    144%        130%            119%                       113%         110%  110%                         88%    23%                    6%    6%     2%              --                 0%    0%                      -15%             -32%              -46% 
 Class::XSAccessor                   11000000/s             1479%                                694%                           484%             446%              322%         196%              184%   181%           156%                    145%        131%            120%                       114%         111%  111%                         89%    23%                    6%    6%     2%              0%                 --    0%                      -14%             -31%              -46% 
 Moo                                 11000000/s             1479%                                694%                           484%             446%              322%         196%              184%   181%           156%                    145%        131%            120%                       114%         111%  111%                         89%    23%                    6%    6%     2%              0%                 0%    --                      -14%             -31%              -46% 
 Class::XSAccessor::Array            13000000/s             1753%                                832%                           585%             541%              396%         248%              233%   230%           201%                    188%        172%            158%                       152%         148%  148%                        122%    45%                   25%   25%    20%             17%                17%   17%                        --             -19%              -37% 
 raw hash access                     17000000/s             2216%                               1065%                           756%             701%              520%         334%              316%   313%           276%                    260%        240%            223%                       215%         210%  210%                        178%    81%                   56%   56%    50%             47%                46%   46%                       25%               --              -21% 
 raw array access                    21000000/s             2857%                               1387%                           993%             922%              691%         455%              431%   427%           380%                    359%        334%            312%                       302%         295%  295%                        255%   131%                  100%   99%    92%             88%                87%   87%                       59%              27%                -- 

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::RW: participant=Object::Tiny::RW
  Object::Tiny::RW::XS: participant=Object::Tiny::RW::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-ScenarioBundle-Accessors.

SOURCE

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

SEE ALSO

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, 2017, 2016 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-ScenarioBundle-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.