NAME

Bencher::Scenario::StringFunctions::Trim - Benchmark string trimming (removing whitespace at the start and end of string)

VERSION

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

SYNOPSIS

To run benchmark with default option:

 % bencher -m StringFunctions::Trim

To run module startup overhead benchmark:

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

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::Trim::More 0.03

String::Trim::NonRegex 0.002

String::Trim::Regex 20210604

String::Util 1.32

Text::Minify::XS v0.4.2

BENCHMARK PARTICIPANTS

  • String::Trim::More::trim (perl_code)

    Function call template:

     String::Trim::More::trim(<str>)
  • String::Trim::NonRegex::trim (perl_code)

    Function call template:

     String::Trim::NonRegex::trim(<str>)
  • String::Trim::Regex::trim (perl_code)

    Function call template:

     String::Trim::Regex::trim(<str>)
  • String::Util::trim (perl_code)

    Function call template:

     String::Util::trim(<str>)
  • Text::Minify::XS::minify (perl_code)

    Function call template:

     Text::Minify::XS::minify(<str>)

BENCHMARK DATASETS

  • empty

  • len10ws1

  • len100ws1

  • len100ws10

  • len100ws100

  • len1000ws1

  • len1000ws10

  • len1000ws100

  • len1000ws1000

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::Trim

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

 #table1#
 {dataset=>"empty"}
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | participant                  | rate (/s) | time (ns) | pct_faster_vs_slowest | pct_slower_vs_fastest |  errors | samples |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | String::Util::trim           |   1770000 |     565   |                 0.00% |               432.57% | 1.7e-10 |      31 |
 | String::Trim::NonRegex::trim |   1950000 |     514   |                 9.87% |               384.71% |   2e-10 |      21 |
 | String::Trim::More::trim     |   7260000 |     138   |               309.61% |                30.02% | 4.6e-11 |      26 |
 | String::Trim::Regex::trim    |   8282000 |     120.7 |               367.56% |                13.90% | 5.8e-12 |      20 |
 | Text::Minify::XS::minify     |   9434000 |     106   |               432.57% |                 0.00% | 5.8e-12 |      20 |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+

The above result formatted in Benchmark.pm style:

              Rate  SU:t  STN:t  STM:t  STR:t  TMX:m 
  SU:t   1770000/s    --    -9%   -75%   -78%   -81% 
  STN:t  1950000/s    9%     --   -73%   -76%   -79% 
  STM:t  7260000/s  309%   272%     --   -12%   -23% 
  STR:t  8282000/s  368%   325%    14%     --   -12% 
  TMX:m  9434000/s  433%   384%    30%    13%     -- 
 
 Legends:
   STM:t: participant=String::Trim::More::trim
   STN:t: participant=String::Trim::NonRegex::trim
   STR:t: participant=String::Trim::Regex::trim
   SU:t: participant=String::Util::trim
   TMX:m: participant=Text::Minify::XS::minify

The above result presented as chart:

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

 #table2#
 {dataset=>"len1000ws1"}
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | participant                  | rate (/s) | time (μs) | pct_faster_vs_slowest | pct_slower_vs_fastest |  errors | samples |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | String::Trim::Regex::trim    |     19000 |   52      |                 0.00% |              6429.62% | 2.1e-07 |      21 |
 | String::Util::trim           |     26100 |   38.3    |                35.13% |              4731.99% | 1.1e-08 |      28 |
 | String::Trim::More::trim     |    479850 |    2.084  |              2384.07% |               162.86% | 5.6e-12 |      20 |
 | Text::Minify::XS::minify     |    514610 |    1.9432 |              2564.06% |               145.10% | 5.8e-12 |      20 |
 | String::Trim::NonRegex::trim |   1261000 |    0.7928 |              6429.62% |                 0.00% | 2.9e-11 |      20 |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+

The above result formatted in Benchmark.pm style:

              Rate  STR:t   SU:t  STM:t  TMX:m  STN:t 
  STR:t    19000/s     --   -26%   -95%   -96%   -98% 
  SU:t     26100/s    35%     --   -94%   -94%   -97% 
  STM:t   479850/s  2395%  1737%     --    -6%   -61% 
  TMX:m   514610/s  2575%  1870%     7%     --   -59% 
  STN:t  1261000/s  6459%  4730%   162%   145%     -- 
 
 Legends:
   STM:t: participant=String::Trim::More::trim
   STN:t: participant=String::Trim::NonRegex::trim
   STR:t: participant=String::Trim::Regex::trim
   SU:t: participant=String::Util::trim
   TMX:m: participant=Text::Minify::XS::minify

The above result presented as chart:

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

 #table3#
 {dataset=>"len1000ws10"}
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | participant                  | rate (/s) | time (μs) | pct_faster_vs_slowest | pct_slower_vs_fastest |  errors | samples |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | String::Trim::Regex::trim    |     19700 |   50.7    |                 0.00% |              2452.07% | 2.3e-08 |      28 |
 | String::Util::trim           |     26100 |   38.3    |                32.38% |              1827.90% | 1.1e-08 |      31 |
 | String::Trim::NonRegex::trim |    367230 |    2.7231 |              1763.21% |                36.97% | 5.8e-12 |      20 |
 | String::Trim::More::trim     |    479870 |    2.0839 |              2334.70% |                 4.82% | 1.7e-11 |      20 |
 | Text::Minify::XS::minify     |    503010 |    1.9881 |              2452.07% |                 0.00% | 5.7e-12 |      20 |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+

The above result formatted in Benchmark.pm style:

             Rate  STR:t   SU:t  STN:t  STM:t  TMX:m 
  STR:t   19700/s     --   -24%   -94%   -95%   -96% 
  SU:t    26100/s    32%     --   -92%   -94%   -94% 
  STN:t  367230/s  1761%  1306%     --   -23%   -26% 
  STM:t  479870/s  2332%  1737%    30%     --    -4% 
  TMX:m  503010/s  2450%  1826%    36%     4%     -- 
 
 Legends:
   STM:t: participant=String::Trim::More::trim
   STN:t: participant=String::Trim::NonRegex::trim
   STR:t: participant=String::Trim::Regex::trim
   SU:t: participant=String::Util::trim
   TMX:m: participant=Text::Minify::XS::minify

The above result presented as chart:

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

 #table4#
 {dataset=>"len1000ws100"}
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | participant                  | rate (/s) | time (μs) | pct_faster_vs_slowest | pct_slower_vs_fastest |  errors | samples |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | String::Trim::Regex::trim    |   19627.3 |   50.9494 |                 0.00% |              2230.43% | 5.8e-12 |      20 |
 | String::Util::trim           |   26000   |   38.4    |                32.70% |              1656.15% | 1.2e-08 |      23 |
 | String::Trim::NonRegex::trim |   46312.2 |   21.5926 |               135.96% |               887.65% | 5.8e-12 |      20 |
 | Text::Minify::XS::minify     |  442000   |    2.26   |              2152.59% |                 3.46% | 8.3e-10 |      20 |
 | String::Trim::More::trim     |  457000   |    2.19   |              2230.43% |                 0.00% |   7e-10 |      28 |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+

The above result formatted in Benchmark.pm style:

              Rate  STR:t   SU:t  STN:t  TMX:m  STM:t 
  STR:t  19627.3/s     --   -24%   -57%   -95%   -95% 
  SU:t     26000/s    32%     --   -43%   -94%   -94% 
  STN:t  46312.2/s   135%    77%     --   -89%   -89% 
  TMX:m   442000/s  2154%  1599%   855%     --    -3% 
  STM:t   457000/s  2226%  1653%   885%     3%     -- 
 
 Legends:
   STM:t: participant=String::Trim::More::trim
   STN:t: participant=String::Trim::NonRegex::trim
   STR:t: participant=String::Trim::Regex::trim
   SU:t: participant=String::Util::trim
   TMX:m: participant=Text::Minify::XS::minify

The above result presented as chart:

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

 #table5#
 {dataset=>"len1000ws1000"}
 +------------------------------+------------+-----------+-----------------------+-----------------------+---------+---------+
 | participant                  | rate (/s)  | time (μs) | pct_faster_vs_slowest | pct_slower_vs_fastest |  errors | samples |
 +------------------------------+------------+-----------+-----------------------+-----------------------+---------+---------+
 | String::Trim::NonRegex::trim |   4713.885 |  212.1392 |                 0.00% |              7207.02% | 5.7e-12 |      22 |
 | String::Trim::Regex::trim    |  19434.1   |   51.456  |               312.27% |              1672.37% | 5.8e-12 |      20 |
 | String::Util::trim           |  25200     |   39.6    |               435.21% |              1265.25% | 1.3e-08 |      20 |
 | Text::Minify::XS::minify     | 206960     |    4.8318 |              4290.51% |                66.43% | 5.6e-12 |      20 |
 | String::Trim::More::trim     | 344000     |    2.9    |              7207.02% |                 0.00% | 7.9e-10 |      22 |
 +------------------------------+------------+-----------+-----------------------+-----------------------+---------+---------+

The above result formatted in Benchmark.pm style:

               Rate  STN:t  STR:t   SU:t  TMX:m  STM:t 
  STN:t  4713.885/s     --   -75%   -81%   -97%   -98% 
  STR:t   19434.1/s   312%     --   -23%   -90%   -94% 
  SU:t      25200/s   435%    29%     --   -87%   -92% 
  TMX:m    206960/s  4290%   964%   719%     --   -39% 
  STM:t    344000/s  7215%  1674%  1265%    66%     -- 
 
 Legends:
   STM:t: participant=String::Trim::More::trim
   STN:t: participant=String::Trim::NonRegex::trim
   STR:t: participant=String::Trim::Regex::trim
   SU:t: participant=String::Util::trim
   TMX:m: participant=Text::Minify::XS::minify

The above result presented as chart:

Result formatted as table (split, part 6 of 9):

 #table6#
 {dataset=>"len100ws1"}
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | participant                  | rate (/s) | time (μs) | pct_faster_vs_slowest | pct_slower_vs_fastest |  errors | samples |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | String::Trim::Regex::trim    |    179120 |    5.5828 |                 0.00% |              1752.41% | 5.6e-12 |      20 |
 | String::Util::trim           |    223280 |    4.4786 |                24.65% |              1386.04% | 5.8e-12 |      30 |
 | String::Trim::More::trim     |   1220000 |    0.82   |               580.87% |               172.07% | 3.5e-10 |      29 |
 | String::Trim::NonRegex::trim |   1300000 |    0.79   |               607.26% |               161.91% | 1.1e-09 |      24 |
 | Text::Minify::XS::minify     |   3318000 |    0.3014 |              1752.41% |                 0.00% | 5.8e-12 |      21 |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+

The above result formatted in Benchmark.pm style:

              Rate  STR:t   SU:t  STM:t  STN:t  TMX:m 
  STR:t   179120/s     --   -19%   -85%   -85%   -94% 
  SU:t    223280/s    24%     --   -81%   -82%   -93% 
  STM:t  1220000/s   580%   446%     --    -3%   -63% 
  STN:t  1300000/s   606%   466%     3%     --   -61% 
  TMX:m  3318000/s  1752%  1385%   172%   162%     -- 
 
 Legends:
   STM:t: participant=String::Trim::More::trim
   STN:t: participant=String::Trim::NonRegex::trim
   STR:t: participant=String::Trim::Regex::trim
   SU:t: participant=String::Util::trim
   TMX:m: participant=Text::Minify::XS::minify

The above result presented as chart:

Result formatted as table (split, part 7 of 9):

 #table7#
 {dataset=>"len100ws10"}
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | participant                  | rate (/s) | time (μs) | pct_faster_vs_slowest | pct_slower_vs_fastest |  errors | samples |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | String::Trim::Regex::trim    |    179120 |    5.5827 |                 0.00% |              1561.52% | 5.7e-12 |      20 |
 | String::Util::trim           |    200000 |    5      |                 1.51% |              1536.81% |   1e-07 |      20 |
 | String::Trim::NonRegex::trim |    367050 |    2.7244 |               104.92% |               710.83% | 5.7e-12 |      20 |
 | String::Trim::More::trim     |   1000000 |    0.9    |               532.42% |               162.73% | 1.2e-08 |      20 |
 | Text::Minify::XS::minify     |   2980000 |    0.336  |              1561.52% |                 0.00% | 3.1e-10 |      20 |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+

The above result formatted in Benchmark.pm style:

              Rate  STR:t   SU:t  STN:t  STM:t  TMX:m 
  STR:t   179120/s     --   -10%   -51%   -83%   -93% 
  SU:t    200000/s    11%     --   -45%   -82%   -93% 
  STN:t   367050/s   104%    83%     --   -66%   -87% 
  STM:t  1000000/s   520%   455%   202%     --   -62% 
  TMX:m  2980000/s  1561%  1388%   710%   167%     -- 
 
 Legends:
   STM:t: participant=String::Trim::More::trim
   STN:t: participant=String::Trim::NonRegex::trim
   STR:t: participant=String::Trim::Regex::trim
   SU:t: participant=String::Util::trim
   TMX:m: participant=Text::Minify::XS::minify

The above result presented as chart:

Result formatted as table (split, part 8 of 9):

 #table8#
 {dataset=>"len100ws100"}
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | participant                  | rate (/s) | time (μs) | pct_faster_vs_slowest | pct_slower_vs_fastest |  errors | samples |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | String::Trim::NonRegex::trim |     46334 |   21.5824 |                 0.00% |              3524.32% | 5.6e-12 |      23 |
 | String::Trim::Regex::trim    |    174000 |    5.75   |               275.55% |               865.08% | 5.2e-09 |      33 |
 | String::Util::trim           |    215000 |    4.64   |               365.00% |               679.43% | 1.7e-09 |      20 |
 | String::Trim::More::trim     |   1100000 |    0.94   |              2189.43% |                58.31% | 1.2e-09 |      23 |
 | Text::Minify::XS::minify     |   1680000 |    0.595  |              3524.32% |                 0.00% | 2.1e-10 |      20 |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+

The above result formatted in Benchmark.pm style:

              Rate  STN:t  STR:t  SU:t  STM:t  TMX:m 
  STN:t    46334/s     --   -73%  -78%   -95%   -97% 
  STR:t   174000/s   275%     --  -19%   -83%   -89% 
  SU:t    215000/s   365%    23%    --   -79%   -87% 
  STM:t  1100000/s  2196%   511%  393%     --   -36% 
  TMX:m  1680000/s  3527%   866%  679%    57%     -- 
 
 Legends:
   STM:t: participant=String::Trim::More::trim
   STN:t: participant=String::Trim::NonRegex::trim
   STR:t: participant=String::Trim::Regex::trim
   SU:t: participant=String::Util::trim
   TMX:m: participant=Text::Minify::XS::minify

The above result presented as chart:

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

 #table9#
 {dataset=>"len10ws1"}
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | participant                  | rate (/s) | time (ns) | pct_faster_vs_slowest | pct_slower_vs_fastest |  errors | samples |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
 | String::Trim::Regex::trim    |    958300 |   1043    |                 0.00% |               718.11% | 1.7e-11 |      20 |
 | String::Util::trim           |    975000 |   1030    |                 1.73% |               704.18% | 4.1e-10 |      21 |
 | String::Trim::NonRegex::trim |   1271500 |    786.48 |                32.68% |               516.62% | 5.6e-12 |      20 |
 | String::Trim::More::trim     |   1600000 |    626    |                66.70% |               390.78% | 2.1e-10 |      20 |
 | Text::Minify::XS::minify     |   7840000 |    128    |               718.11% |                 0.00% | 1.7e-11 |      21 |
 +------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+

The above result formatted in Benchmark.pm style:

              Rate  STR:t  SU:t  STN:t  STM:t  TMX:m 
  STR:t   958300/s     --   -1%   -24%   -39%   -87% 
  SU:t    975000/s     1%    --   -23%   -39%   -87% 
  STN:t  1271500/s    32%   30%     --   -20%   -83% 
  STM:t  1600000/s    66%   64%    25%     --   -79% 
  TMX:m  7840000/s   714%  704%   514%   389%     -- 
 
 Legends:
   STM:t: participant=String::Trim::More::trim
   STN:t: participant=String::Trim::NonRegex::trim
   STR:t: participant=String::Trim::Regex::trim
   SU:t: participant=String::Util::trim
   TMX:m: participant=Text::Minify::XS::minify

The above result presented as chart:

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

Result formatted as table:

 #table10#
 +------------------------+-----------+-------------------+-----------------------+-----------------------+-----------+---------+
 | participant            | time (ms) | mod_overhead_time | pct_faster_vs_slowest | pct_slower_vs_fastest |  errors   | samples |
 +------------------------+-----------+-------------------+-----------------------+-----------------------+-----------+---------+
 | String::Util           |      10   |               5.1 |                 0.00% |               136.80% |   0.00019 |      20 |
 | String::Trim::Regex    |      10   |               5.1 |                13.78% |               108.12% |   0.00025 |      20 |
 | Text::Minify::XS       |       8   |               3.1 |                44.40% |                63.99% |   0.00013 |      22 |
 | String::Trim::NonRegex |       8   |               3.1 |                46.20% |                61.97% |   0.00021 |      20 |
 | String::Trim::More     |       8   |               3.1 |                51.23% |                56.58% |   0.00019 |      20 |
 | perl -e1 (baseline)    |       4.9 |               0   |               136.80% |                 0.00% | 9.9e-06   |      20 |
 +------------------------+-----------+-------------------+-----------------------+-----------------------+-----------+---------+

The above result formatted in Benchmark.pm style:

                Rate   S:U  ST:R  TM:X  ST:N  ST:M  :perl -e1 ( 
  S:U          0.1/s    --    0%  -19%  -19%  -19%         -51% 
  ST:R         0.1/s    0%    --  -19%  -19%  -19%         -51% 
  TM:X         0.1/s   25%   25%    --    0%    0%         -38% 
  ST:N         0.1/s   25%   25%    0%    --    0%         -38% 
  ST:M         0.1/s   25%   25%    0%    0%    --         -38% 
  :perl -e1 (  0.2/s  104%  104%   63%   63%   63%           -- 
 
 Legends:
   :perl -e1 (: mod_overhead_time=0 participant=perl -e1 (baseline)
   S:U: mod_overhead_time=5.1 participant=String::Util
   ST:M: mod_overhead_time=3.1 participant=String::Trim::More
   ST:N: mod_overhead_time=3.1 participant=String::Trim::NonRegex
   ST:R: mod_overhead_time=5.1 participant=String::Trim::Regex
   TM:X: mod_overhead_time=3.1 participant=Text::Minify::XS

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