NAME

Bencher::Scenario::StringFunctions::Indent - Benchmark string indenting (adding whitespace to lines of text)

VERSION

This document describes version 0.006 of Bencher::Scenario::StringFunctions::Indent (from Perl distribution Bencher-Scenarios-StringFunctions), released on 2022-03-27.

SYNOPSIS

To run benchmark with default option:

 % bencher -m StringFunctions::Indent

To run module startup overhead benchmark:

 % bencher --module-startup -m StringFunctions::Indent

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.

String::Nudge 1.0002

String::Indent 0.03

String::Indent::Join

BENCHMARK PARTICIPANTS

  • String::Nudge::nudge (perl_code)

    Function call template:

     String::Nudge::nudge(<num_spaces>, <str>)
  • String::Indent::indent (perl_code)

    Function call template:

     String::Indent::indent(<indent>, <str>)
  • String::Indent::Join::indent (perl_code)

    Function call template:

     String::Indent::Join::indent(<indent>, <str>)

BENCHMARK DATASETS

  • empty

  • 1line

  • 10line

  • 100line

  • 1000line

SAMPLE BENCHMARK RESULTS

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

Benchmark with default options (bencher -m StringFunctions::Indent):

 #table1#
 {dataset=>"1000line"}
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | participant                  | rate (/s) | time (μs) | pct_faster_vs_slowest | pct_slower_vs_fastest |  errors | samples |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | String::Indent::indent       |      2570 |       390 |                 0.00% |                47.77% | 1.6e-07 |      20 |
 | String::Nudge::nudge         |      3650 |       274 |                42.25% |                 3.88% | 2.1e-07 |      20 |
 | String::Indent::Join::indent |      3790 |       264 |                47.77% |                 0.00% | 2.1e-07 |      20 |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+

Formatted as Benchmark.pm result:

           Rate  SI:i  SN:n  SIJ:i 
  SI:i   2570/s    --  -29%   -32% 
  SN:n   3650/s   42%    --    -3% 
  SIJ:i  3790/s   47%    3%     -- 
 
 Legends:
   SI:i: participant=String::Indent::indent
   SIJ:i: participant=String::Indent::Join::indent
   SN:n: participant=String::Nudge::nudge
 #table2#
 {dataset=>"100line"}
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | participant                  | rate (/s) | time (μs) | pct_faster_vs_slowest | pct_slower_vs_fastest |  errors | samples |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | String::Indent::indent       |     24000 |      41.7 |                 0.00% |                72.08% | 1.1e-08 |      28 |
 | String::Nudge::nudge         |     33400 |      29.9 |                39.57% |                23.29% | 1.2e-08 |      26 |
 | String::Indent::Join::indent |     41200 |      24.3 |                72.08% |                 0.00% | 6.4e-09 |      22 |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+

Formatted as Benchmark.pm result:

            Rate  SI:i  SN:n  SIJ:i 
  SI:i   24000/s    --  -28%   -41% 
  SN:n   33400/s   39%    --   -18% 
  SIJ:i  41200/s   71%   23%     -- 
 
 Legends:
   SI:i: participant=String::Indent::indent
   SIJ:i: participant=String::Indent::Join::indent
   SN:n: participant=String::Nudge::nudge
 #table3#
 {dataset=>"10line"}
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | participant                  | rate (/s) | time (μs) | pct_faster_vs_slowest | pct_slower_vs_fastest |  errors | samples |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | String::Indent::indent       |    188000 |      5.33 |                 0.00% |                95.85% | 1.7e-09 |      20 |
 | String::Nudge::nudge         |    249000 |      4.02 |                32.76% |                47.52% | 1.6e-09 |      23 |
 | String::Indent::Join::indent |    367000 |      2.72 |                95.85% |                 0.00% | 8.3e-10 |      20 |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+

Formatted as Benchmark.pm result:

             Rate  SI:i  SN:n  SIJ:i 
  SI:i   188000/s    --  -24%   -48% 
  SN:n   249000/s   32%    --   -32% 
  SIJ:i  367000/s   95%   47%     -- 
 
 Legends:
   SI:i: participant=String::Indent::indent
   SIJ:i: participant=String::Indent::Join::indent
   SN:n: participant=String::Nudge::nudge
 #table4#
 {dataset=>"1line"}
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | participant                  | rate (/s) | time (ns) | pct_faster_vs_slowest | pct_slower_vs_fastest |  errors | samples |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | String::Indent::indent       |    724000 |      1380 |                 0.00% |               166.48% | 4.2e-10 |      20 |
 | String::Nudge::nudge         |    876000 |      1140 |                20.99% |               120.26% | 4.2e-10 |      20 |
 | String::Indent::Join::indent |   1930000 |       518 |               166.48% |                 0.00% | 1.7e-11 |      30 |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+

Formatted as Benchmark.pm result:

              Rate  SI:i  SN:n  SIJ:i 
  SI:i    724000/s    --  -17%   -62% 
  SN:n    876000/s   21%    --   -54% 
  SIJ:i  1930000/s  166%  120%     -- 
 
 Legends:
   SI:i: participant=String::Indent::indent
   SIJ:i: participant=String::Indent::Join::indent
   SN:n: participant=String::Nudge::nudge
 #table5#
 {dataset=>"empty"}
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | participant                  | rate (/s) | time (ns) | pct_faster_vs_slowest | pct_slower_vs_fastest |  errors | samples |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | String::Indent::indent       |    745620 |    1341.2 |                 0.00% |               595.24% | 5.8e-12 |      20 |
 | String::Nudge::nudge         |   1020000 |     978   |                37.10% |               407.10% | 4.2e-10 |      20 |
 | String::Indent::Join::indent |   5180000 |     193   |               595.24% |                 0.00% | 9.5e-11 |      24 |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+

Formatted as Benchmark.pm result:

              Rate  SI:i  SN:n  SIJ:i 
  SI:i    745620/s    --  -27%   -85% 
  SN:n   1020000/s   37%    --   -80% 
  SIJ:i  5180000/s  594%  406%     -- 
 
 Legends:
   SI:i: participant=String::Indent::indent
   SIJ:i: participant=String::Indent::Join::indent
   SN:n: participant=String::Nudge::nudge

Benchmark module startup overhead (bencher -m StringFunctions::Indent --module-startup):

 #table6#
 +----------------------+-----------+-------------------+-----------------------+-----------------------+-----------+---------+
 | participant          | time (ms) | mod_overhead_time | pct_faster_vs_slowest | pct_slower_vs_fastest |  errors   | samples |
 +----------------------+-----------+-------------------+-----------------------+-----------------------+-----------+---------+
 | String::Indent       |       8.9 |               1.9 |                 0.00% |                20.55% | 1.2e-05   |      20 |
 | String::Nudge        |       8.9 |               1.9 |                 0.08% |                20.45% | 1.2e-05   |      21 |
 | String::Indent::Join |       8.8 |               1.8 |                 1.30% |                19.00% | 1.3e-05   |      20 |
 | perl -e1 (baseline)  |       7   |               0   |                20.55% |                 0.00% |   0.00019 |      20 |
 +----------------------+-----------+-------------------+-----------------------+-----------------------+-----------+---------+

Formatted as Benchmark.pm result:

                          Rate  S:I  S:N  SI:J  perl -e1 (baseline) 
  S:I                  112.4/s   --   0%   -1%                 -21% 
  S:N                  112.4/s   0%   --   -1%                 -21% 
  SI:J                 113.6/s   1%   1%    --                 -20% 
  perl -e1 (baseline)  142.9/s  27%  27%   25%                   -- 
 
 Legends:
   S:I: mod_overhead_time=1.9 participant=String::Indent
   S:N: mod_overhead_time=1.9 participant=String::Nudge
   SI:J: mod_overhead_time=1.8 participant=String::Indent::Join
   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

Joining is faster than regex substitution for the datasets tested (0-1000 lines of short text).

HOMEPAGE

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

SOURCE

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

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, and sometimes one or two other Dist::Zilla plugin and/or Pod::Weaver::Plugin. Any additional steps required beyond that are considered a bug and can be reported to me.

COPYRIGHT AND LICENSE

This software is copyright (c) 2022, 2021, 2018 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-Scenarios-StringFunctions

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.