NAME

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

VERSION

This document describes version 0.005 of Bencher::Scenario::StringFunctions::Indent (from Perl distribution Bencher-Scenarios-StringFunctions), released on 2021-07-31.

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

BENCHMARK SAMPLE RESULTS

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 StringFunctions::Indent

Result formatted as table (split, part 1 of 5):

 #table1#
 {dataset=>"1000line"}
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | participant                  | rate (/s) | time (μs) | pct_faster_vs_slowest | pct_slower_vs_fastest |  errors | samples |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | String::Indent::indent       |  3000     |  333      |                 0.00% |                61.96% | 4.9e-08 |      24 |
 | String::Nudge::nudge         |  3990     |  251      |                33.01% |                21.76% | 2.1e-07 |      20 |
 | String::Indent::Join::indent |  4859.002 |  205.8036 |                61.96% |                 0.00% | 5.6e-12 |      21 |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+

The above result formatted in Benchmark.pm style:

               Rate  SI:i  SN:n  SIJ:i 
  SI:i       3000/s    --  -24%   -38% 
  SN:n       3990/s   32%    --   -18% 
  SIJ:i  4859.002/s   61%   21%     -- 
 
 Legends:
   SI:i: participant=String::Indent::indent
   SIJ:i: participant=String::Indent::Join::indent
   SN:n: participant=String::Nudge::nudge

The above result presented as chart:

Result formatted as table (split, part 2 of 5):

 #table2#
 {dataset=>"100line"}
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | participant                  | rate (/s) | time (μs) | pct_faster_vs_slowest | pct_slower_vs_fastest |  errors | samples |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | String::Indent::indent       |   28400   |   35.3    |                 0.00% |                87.83% | 1.2e-08 |      26 |
 | String::Nudge::nudge         |   37437.5 |   26.7112 |                32.05% |                42.24% | 5.8e-12 |      20 |
 | String::Indent::Join::indent |   53300   |   18.8    |                87.83% |                 0.00% | 6.7e-09 |      20 |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+

The above result formatted in Benchmark.pm style:

              Rate  SI:i  SN:n  SIJ:i 
  SI:i     28400/s    --  -24%   -46% 
  SN:n   37437.5/s   32%    --   -29% 
  SIJ:i    53300/s   87%   42%     -- 
 
 Legends:
   SI:i: participant=String::Indent::indent
   SIJ:i: participant=String::Indent::Join::indent
   SN:n: participant=String::Nudge::nudge

The above result presented as chart:

Result formatted as table (split, part 3 of 5):

 #table3#
 {dataset=>"10line"}
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | participant                  | rate (/s) | time (μs) | pct_faster_vs_slowest | pct_slower_vs_fastest |  errors | samples |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | String::Indent::indent       |    218140 |    4.5843 |                 0.00% |               110.87% | 1.7e-11 |      20 |
 | String::Nudge::nudge         |    279260 |    3.5808 |                28.02% |                64.71% | 5.8e-12 |      20 |
 | String::Indent::Join::indent |    459980 |    2.174  |               110.87% |                 0.00% | 5.8e-12 |      20 |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+

The above result formatted in Benchmark.pm style:

             Rate  SI:i  SN:n  SIJ:i 
  SI:i   218140/s    --  -21%   -52% 
  SN:n   279260/s   28%    --   -39% 
  SIJ:i  459980/s  110%   64%     -- 
 
 Legends:
   SI:i: participant=String::Indent::indent
   SIJ:i: participant=String::Indent::Join::indent
   SN:n: participant=String::Nudge::nudge

The above result presented as chart:

Result formatted as table (split, part 4 of 5):

 #table4#
 {dataset=>"1line"}
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | participant                  | rate (/s) | time (ns) | pct_faster_vs_slowest | pct_slower_vs_fastest |  errors | samples |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | String::Indent::indent       |    822660 |    1215.6 |                 0.00% |               179.86% | 5.8e-12 |      20 |
 | String::Nudge::nudge         |   1040000 |     962   |                26.42% |               121.37% | 3.8e-10 |      24 |
 | String::Indent::Join::indent |   2302000 |     434.3 |               179.86% |                 0.00% | 5.6e-12 |      20 |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+

The above result formatted in Benchmark.pm style:

              Rate  SI:i  SN:n  SIJ:i 
  SI:i    822660/s    --  -20%   -64% 
  SN:n   1040000/s   26%    --   -54% 
  SIJ:i  2302000/s  179%  121%     -- 
 
 Legends:
   SI:i: participant=String::Indent::indent
   SIJ:i: participant=String::Indent::Join::indent
   SN:n: participant=String::Nudge::nudge

The above result presented as chart:

Result formatted as table (split, part 5 of 5):

 #table5#
 {dataset=>"empty"}
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | participant                  | rate (/s) | time (ns) | pct_faster_vs_slowest | pct_slower_vs_fastest |  errors | samples |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | String::Indent::indent       |    867600 |    1153   |                 0.00% |               591.98% | 1.7e-11 |      20 |
 | String::Nudge::nudge         |   1200000 |     850   |                35.15% |               412.01% | 1.2e-09 |      21 |
 | String::Indent::Join::indent |   6004000 |     166.6 |               591.98% |                 0.00% | 5.7e-12 |      20 |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+

The above result formatted in Benchmark.pm style:

              Rate  SI:i  SN:n  SIJ:i 
  SI:i    867600/s    --  -26%   -85% 
  SN:n   1200000/s   35%    --   -80% 
  SIJ:i  6004000/s  592%  410%     -- 
 
 Legends:
   SI:i: participant=String::Indent::indent
   SIJ:i: participant=String::Indent::Join::indent
   SN:n: participant=String::Nudge::nudge

The above result presented as chart:

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

Result formatted as table:

 #table6#
 +----------------------+-----------+-------------------+-----------------------+-----------------------+---------+---------+
 | participant          | time (ms) | mod_overhead_time | pct_faster_vs_slowest | pct_slower_vs_fastest |  errors | samples |
 +----------------------+-----------+-------------------+-----------------------+-----------------------+---------+---------+
 | String::Nudge        |         8 |                 2 |                 0.00% |                42.10% | 0.00013 |      20 |
 | String::Indent::Join |         8 |                 2 |                 4.35% |                36.19% | 0.00017 |      20 |
 | String::Indent       |         8 |                 2 |                 7.06% |                32.74% | 0.00013 |      21 |
 | perl -e1 (baseline)  |         6 |                 0 |                42.10% |                 0.00% | 0.00012 |      20 |
 +----------------------+-----------+-------------------+-----------------------+-----------------------+---------+---------+

The above result formatted in Benchmark.pm style:

                Rate  S:N  SI:J  S:I  :perl -e1 ( 
  S:N          0.1/s   --    0%   0%         -25% 
  SI:J         0.1/s   0%    --   0%         -25% 
  S:I          0.1/s   0%    0%   --         -25% 
  :perl -e1 (  0.2/s  33%   33%  33%           -- 
 
 Legends:
   :perl -e1 (: mod_overhead_time=0 participant=perl -e1 (baseline)
   S:I: mod_overhead_time=2 participant=String::Indent
   S:N: mod_overhead_time=2 participant=String::Nudge
   SI:J: mod_overhead_time=2 participant=String::Indent::Join

The above result presented as chart:

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.

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.

AUTHOR

perlancar <perlancar@cpan.org>

COPYRIGHT AND LICENSE

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