NAME

Bencher::Scenario::SmartMatch::str_in_ary_of_str - Benchmark searching string in array-of-string using smartmatch: $str ~~ @ary_of_str

VERSION

This document describes version 0.001 of Bencher::Scenario::SmartMatch::str_in_ary_of_str (from Perl distribution Bencher-ScenarioBundle-SmartMatch), released on 2024-07-02.

SYNOPSIS

To run benchmark with default option:

% bencher -m SmartMatch::str_in_ary_of_str

To run module startup overhead benchmark:

% bencher --module-startup -m SmartMatch::str_in_ary_of_str

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.

match::simple 0.012

Switch::Right 0.000005

BENCHMARK PARTICIPANTS

  • match::simple (perl_code)

    Code template:

    my $str = <str>; my $ary = <ary>; for (1..100) { match::simple::match($str, $ary) } 
  • Switch::Right (perl_code)

    Code template:

    my $str = <str>; my $ary = <ary>; for (1..100) { Switch::Right::smartmatch($str, $ary) } 

BENCHMARK DATASETS

  • 0-str

  • 1-str-found

  • 10-str-found-at-the-beginning

  • 10-str-found-at-the-end

  • 1000-str-found-at-the-end

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 SmartMatch::str_in_ary_of_str

Result formatted as table:

#table1#
+---------------+-------------------------------+-----------+-----------+-----------------------+-----------------------+-----------+---------+
| participant   | dataset                       | rate (/s) | time (ms) | pct_faster_vs_slowest | pct_slower_vs_fastest |  errors   | samples |
+---------------+-------------------------------+-----------+-----------+-----------------------+-----------------------+-----------+---------+
| Switch::Right | 1000-str-found-at-the-end     |      31   |   33      |                 0.00% |             37393.25% |   0.00014 |      20 |
| match::simple | 1000-str-found-at-the-end     |      32.1 |   31.2    |                 4.79% |             35678.64% | 5.1e-06   |      21 |
| Switch::Right | 0-str                         |      30   |   30      |                 9.95% |             33999.86% |   0.00047 |      21 |
| Switch::Right | 10-str-found-at-the-end       |      30   |   30      |                10.75% |             33753.46% |   0.00063 |      20 |
| Switch::Right | 10-str-found-at-the-beginning |      40   |   30      |                16.42% |             32104.46% |   0.00037 |      20 |
| Switch::Right | 1-str-found                   |      37.7 |   26.5    |                23.27% |             30316.50% | 1.4e-05   |      23 |
| match::simple | 10-str-found-at-the-end       |    2460   |    0.407  |              7934.37% |               366.66% | 6.8e-08   |      20 |
| match::simple | 10-str-found-at-the-beginning |    8150   |    0.123  |             26543.33% |                40.72% | 3.9e-08   |      20 |
| match::simple | 1-str-found                   |    8310   |    0.12   |             27061.90% |                38.04% |   6e-08   |      21 |
| match::simple | 0-str                         |   11500   |    0.0871 |             37393.25% |                 0.00% | 2.9e-08   |      20 |
+---------------+-------------------------------+-----------+-----------+-----------------------+-----------------------+-----------+---------+

The above result formatted in Benchmark.pm style:

                                       Rate  S:R 1000-str-found-at-the-end  m:s 1000-str-found-at-the-end  S:R 0-str  S:R 10-str-found-at-the-end  S:R 10-str-found-at-the-beginning  S:R 1-str-found  m:s 10-str-found-at-the-end  m:s 10-str-found-at-the-beginning  m:s 1-str-found  m:s 0-str 
 S:R 1000-str-found-at-the-end         31/s                             --                            -5%        -9%                          -9%                                -9%             -19%                         -98%                               -99%             -99%       -99% 
 m:s 1000-str-found-at-the-end       32.1/s                             5%                             --        -3%                          -3%                                -3%             -15%                         -98%                               -99%             -99%       -99% 
 S:R 0-str                             30/s                            10%                             4%         --                           0%                                 0%             -11%                         -98%                               -99%             -99%       -99% 
 S:R 10-str-found-at-the-end           30/s                            10%                             4%         0%                           --                                 0%             -11%                         -98%                               -99%             -99%       -99% 
 S:R 10-str-found-at-the-beginning     40/s                            10%                             4%         0%                           0%                                 --             -11%                         -98%                               -99%             -99%       -99% 
 S:R 1-str-found                     37.7/s                            24%                            17%        13%                          13%                                13%               --                         -98%                               -99%             -99%       -99% 
 m:s 10-str-found-at-the-end         2460/s                          8008%                          7565%      7271%                        7271%                              7271%            6411%                           --                               -69%             -70%       -78% 
 m:s 10-str-found-at-the-beginning   8150/s                         26729%                         25265%     24290%                       24290%                             24290%           21444%                         230%                                 --              -2%       -29% 
 m:s 1-str-found                     8310/s                         27400%                         25900%     24900%                       24900%                             24900%           21983%                         239%                                 2%               --       -27% 
 m:s 0-str                          11500/s                         37787%                         35720%     34343%                       34343%                             34343%           30324%                         367%                                41%              37%         -- 

Legends:
  S:R 0-str: dataset=0-str participant=Switch::Right
  S:R 1-str-found: dataset=1-str-found participant=Switch::Right
  S:R 10-str-found-at-the-beginning: dataset=10-str-found-at-the-beginning participant=Switch::Right
  S:R 10-str-found-at-the-end: dataset=10-str-found-at-the-end participant=Switch::Right
  S:R 1000-str-found-at-the-end: dataset=1000-str-found-at-the-end participant=Switch::Right
  m:s 0-str: dataset=0-str participant=match::simple
  m:s 1-str-found: dataset=1-str-found participant=match::simple
  m:s 10-str-found-at-the-beginning: dataset=10-str-found-at-the-beginning participant=match::simple
  m:s 10-str-found-at-the-end: dataset=10-str-found-at-the-end participant=match::simple
  m:s 1000-str-found-at-the-end: dataset=1000-str-found-at-the-end participant=match::simple

Sample benchmark #2

Benchmark command (benchmarking module startup overhead):

% bencher -m SmartMatch::str_in_ary_of_str --module-startup

Result formatted as table:

#table2#
+---------------------+-----------+-------------------+-----------------------+-----------------------+-----------+---------+
| participant         | time (ms) | mod_overhead_time | pct_faster_vs_slowest | pct_slower_vs_fastest |  errors   | samples |
+---------------------+-----------+-------------------+-----------------------+-----------------------+-----------+---------+
| Switch::Right       |     770   |             762.6 |                 0.00% |             10343.68% |   0.0047  |      20 |
| match::simple       |      21   |              13.6 |              3543.36% |               186.65% |   0.00013 |      20 |
| perl -e1 (baseline) |       7.4 |               0   |             10343.68% |                 0.00% | 3.8e-05   |      20 |
+---------------------+-----------+-------------------+-----------------------+-----------------------+-----------+---------+

The above result formatted in Benchmark.pm style:

                         Rate     S:R   m:s  perl -e1 (baseline) 
 S:R                    1.3/s      --  -97%                 -99% 
 m:s                   47.6/s   3566%    --                 -64% 
 perl -e1 (baseline)  135.1/s  10305%  183%                   -- 

Legends:
  S:R: mod_overhead_time=762.6 participant=Switch::Right
  m:s: mod_overhead_time=13.6 participant=match::simple
  perl -e1 (baseline): mod_overhead_time=0 participant=perl -e1 (baseline)

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

BENCHMARK NOTES

Each participant code does a 100x matching.

On my system, Switch::Right seems to have the base overhead of ~0.25ms even for the simplest string and shortest array. So as cool as that module is, for most practical purposes it's a no-go.

HOMEPAGE

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

SOURCE

Source repository is at https://github.com/perlancar/perl-Bencher-ScenarioBundle-SmartMatch.

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 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-SmartMatch

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.