NAME
Bencher::Scenario::StringFunctions::Trim - Benchmark string trimming (removing whitespace at the start and end of string)
VERSION
This document describes version 0.006 of Bencher::Scenario::StringFunctions::Trim (from Perl distribution Bencher-Scenarios-StringFunctions), released on 2022-03-27.
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.6.1
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>)
Text::Minify::XS::minify_ascii (perl_code)
Function call template:
Text::Minify::XS::minify_ascii(<str>)
BENCHMARK DATASETS
empty
len10ws1
len100ws1
len100ws10
len100ws100
len1000ws1
len1000ws10
len1000ws100
len1000ws1000
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::Trim
):
#table1#
{dataset=>"empty"}
+--------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
| participant | rate (/s) | time (ns) | pct_faster_vs_slowest | pct_slower_vs_fastest | errors | samples |
+--------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
| String::Util::trim | 1494940 | 668.924 | 0.00% | 444.35% | 0 | 22 |
| String::Trim::NonRegex::trim | 1574290 | 635.205 | 5.31% | 416.91% | 0 | 24 |
| String::Trim::More::trim | 3900000 | 260 | 157.92% | 111.05% | 4.4e-10 | 20 |
| String::Trim::Regex::trim | 5850660 | 170.921 | 291.36% | 39.09% | 0 | 20 |
| Text::Minify::XS::minify | 8120000 | 123 | 443.46% | 0.16% | 4.6e-11 | 26 |
| Text::Minify::XS::minify_ascii | 8100000 | 120 | 444.35% | 0.00% | 2.1e-10 | 20 |
+--------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
Formatted as Benchmark.pm result:
Rate SU:t STN:t STM:t STR:t TMX:m TMX:m_a
SU:t 1494940/s -- -5% -61% -74% -81% -82%
STN:t 1574290/s 5% -- -59% -73% -80% -81%
STM:t 3900000/s 157% 144% -- -34% -52% -53%
STR:t 5850660/s 291% 271% 52% -- -28% -29%
TMX:m 8120000/s 443% 416% 111% 38% -- -2%
TMX:m_a 8100000/s 457% 429% 116% 42% 2% --
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
TMX:m_a: participant=Text::Minify::XS::minify_ascii
#table2#
{dataset=>"len1000ws1"}
+--------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
| participant | rate (/s) | time (μs) | pct_faster_vs_slowest | pct_slower_vs_fastest | errors | samples |
+--------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
| String::Trim::Regex::trim | 18025.2 | 55.4778 | 0.00% | 5589.45% | 0 | 20 |
| String::Util::trim | 23135.7 | 43.2232 | 28.35% | 4332.70% | 5.8e-12 | 20 |
| Text::Minify::XS::minify | 317000 | 3.15 | 1660.22% | 223.22% | 1.5e-09 | 24 |
| String::Trim::More::trim | 382825 | 2.61216 | 2023.83% | 167.89% | 0 | 21 |
| Text::Minify::XS::minify_ascii | 405721 | 2.46475 | 2150.85% | 152.77% | 0 | 20 |
| String::Trim::NonRegex::trim | 1000000 | 0.98 | 5589.45% | 0.00% | 1.2e-09 | 20 |
+--------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
Formatted as Benchmark.pm result:
Rate STR:t SU:t TMX:m STM:t TMX:m_a STN:t
STR:t 18025.2/s -- -22% -94% -95% -95% -98%
SU:t 23135.7/s 28% -- -92% -93% -94% -97%
TMX:m 317000/s 1661% 1272% -- -17% -21% -68%
STM:t 382825/s 2023% 1554% 20% -- -5% -62%
TMX:m_a 405721/s 2150% 1653% 27% 5% -- -60%
STN:t 1000000/s 5561% 4310% 221% 166% 151% --
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
TMX:m_a: participant=Text::Minify::XS::minify_ascii
#table3#
{dataset=>"len1000ws10"}
+--------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
| participant | rate (/s) | time (μs) | pct_faster_vs_slowest | pct_slower_vs_fastest | errors | samples |
+--------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
| String::Trim::Regex::trim | 18100 | 55.4 | 0.00% | 2117.58% | 2.4e-08 | 25 |
| String::Util::trim | 23100 | 43.2 | 28.18% | 1630.11% | 9.9e-09 | 36 |
| String::Trim::NonRegex::trim | 300724 | 3.32531 | 1566.06% | 33.10% | 0 | 20 |
| Text::Minify::XS::minify | 312634 | 3.19863 | 1632.04% | 28.03% | 0 | 20 |
| String::Trim::More::trim | 383685 | 2.60631 | 2025.68% | 4.32% | 0 | 20 |
| Text::Minify::XS::minify_ascii | 400273 | 2.49829 | 2117.58% | 0.00% | 0 | 20 |
+--------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
Formatted as Benchmark.pm result:
Rate STR:t SU:t STN:t TMX:m STM:t TMX:m_a
STR:t 18100/s -- -22% -93% -94% -95% -95%
SU:t 23100/s 28% -- -92% -92% -93% -94%
STN:t 300724/s 1566% 1199% -- -3% -21% -24%
TMX:m 312634/s 1631% 1250% 3% -- -18% -21%
STM:t 383685/s 2025% 1557% 27% 22% -- -4%
TMX:m_a 400273/s 2117% 1629% 33% 28% 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
TMX:m_a: participant=Text::Minify::XS::minify_ascii
#table4#
{dataset=>"len1000ws100"}
+--------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
| participant | rate (/s) | time (μs) | pct_faster_vs_slowest | pct_slower_vs_fastest | errors | samples |
+--------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
| String::Trim::Regex::trim | 18000 | 55.6 | 0.00% | 1900.90% | 2.2e-08 | 30 |
| String::Util::trim | 23008.8 | 43.4616 | 28.04% | 1462.70% | 0 | 20 |
| String::Trim::NonRegex::trim | 34000 | 29 | 91.13% | 946.90% | 1.1e-07 | 22 |
| Text::Minify::XS::minify | 267998 | 3.73137 | 1391.38% | 34.17% | 0 | 20 |
| Text::Minify::XS::minify_ascii | 351980 | 2.8411 | 1858.74% | 2.15% | 5.7e-12 | 20 |
| String::Trim::More::trim | 359560 | 2.78118 | 1900.90% | 0.00% | 0 | 20 |
+--------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
Formatted as Benchmark.pm result:
Rate STR:t SU:t STN:t TMX:m TMX:m_a STM:t
STR:t 18000/s -- -21% -47% -93% -94% -94%
SU:t 23008.8/s 27% -- -33% -91% -93% -93%
STN:t 34000/s 91% 49% -- -87% -90% -90%
TMX:m 267998/s 1390% 1064% 677% -- -23% -25%
TMX:m_a 351980/s 1856% 1429% 920% 31% -- -2%
STM:t 359560/s 1899% 1462% 942% 34% 2% --
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
TMX:m_a: participant=Text::Minify::XS::minify_ascii
#table5#
{dataset=>"len1000ws1000"}
+--------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
| participant | rate (/s) | time (μs) | pct_faster_vs_slowest | pct_slower_vs_fastest | errors | samples |
+--------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
| String::Trim::NonRegex::trim | 4000 | 300 | 0.00% | 6621.30% | 3.6e-06 | 20 |
| String::Trim::Regex::trim | 17614.9 | 56.7701 | 363.96% | 1348.68% | 0 | 25 |
| String::Util::trim | 22300 | 44.8 | 488.22% | 1042.65% | 1.2e-08 | 25 |
| Text::Minify::XS::minify | 122000 | 8.17 | 3124.73% | 108.43% | 3.1e-09 | 23 |
| Text::Minify::XS::minify_ascii | 179361 | 5.57536 | 4624.19% | 42.27% | 0 | 20 |
| String::Trim::More::trim | 255184 | 3.91875 | 6621.30% | 0.00% | 0 | 20 |
+--------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
Formatted as Benchmark.pm result:
Rate STN:t STR:t SU:t TMX:m TMX:m_a STM:t
STN:t 4000/s -- -81% -85% -97% -98% -98%
STR:t 17614.9/s 428% -- -21% -85% -90% -93%
SU:t 22300/s 569% 26% -- -81% -87% -91%
TMX:m 122000/s 3571% 594% 448% -- -31% -52%
TMX:m_a 179361/s 5280% 918% 703% 46% -- -29%
STM:t 255184/s 7555% 1348% 1043% 108% 42% --
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
TMX:m_a: participant=Text::Minify::XS::minify_ascii
#table6#
{dataset=>"len100ws1"}
+--------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
| participant | rate (/s) | time (μs) | pct_faster_vs_slowest | pct_slower_vs_fastest | errors | samples |
+--------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
| String::Trim::Regex::trim | 162832 | 6.14131 | 0.00% | 1567.19% | 0 | 20 |
| String::Util::trim | 195849 | 5.10598 | 20.28% | 1286.13% | 0 | 20 |
| String::Trim::More::trim | 900000 | 1 | 442.82% | 207.14% | 1.4e-08 | 20 |
| String::Trim::NonRegex::trim | 1000000 | 0.96 | 538.52% | 161.10% | 1.7e-09 | 20 |
| Text::Minify::XS::minify | 2310000 | 0.432 | 1320.87% | 17.34% | 9e-11 | 20 |
| Text::Minify::XS::minify_ascii | 2714720 | 0.368362 | 1567.19% | 0.00% | 0 | 20 |
+--------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
Formatted as Benchmark.pm result:
Rate STR:t SU:t STM:t STN:t TMX:m TMX:m_a
STR:t 162832/s -- -16% -83% -84% -92% -94%
SU:t 195849/s 20% -- -80% -81% -91% -92%
STM:t 900000/s 514% 410% -- -4% -56% -63%
STN:t 1000000/s 539% 431% 4% -- -55% -61%
TMX:m 2310000/s 1321% 1081% 131% 122% -- -14%
TMX:m_a 2714720/s 1567% 1286% 171% 160% 17% --
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
TMX:m_a: participant=Text::Minify::XS::minify_ascii
#table7#
{dataset=>"len100ws10"}
+--------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
| participant | rate (/s) | time (μs) | pct_faster_vs_slowest | pct_slower_vs_fastest | errors | samples |
+--------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
| String::Trim::Regex::trim | 163000 | 6.14 | 0.00% | 1458.96% | 1.4e-09 | 27 |
| String::Util::trim | 196000 | 5.11 | 20.08% | 1198.31% | 1.6e-09 | 21 |
| String::Trim::NonRegex::trim | 302000 | 3.31 | 85.47% | 740.53% | 1.7e-09 | 20 |
| String::Trim::More::trim | 1035120 | 0.966073 | 535.12% | 145.46% | 0 | 32 |
| Text::Minify::XS::minify | 2110000 | 0.474 | 1194.32% | 20.45% | 2.9e-10 | 26 |
| Text::Minify::XS::minify_ascii | 2540780 | 0.39358 | 1458.96% | 0.00% | 0 | 24 |
+--------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
Formatted as Benchmark.pm result:
Rate STR:t SU:t STN:t STM:t TMX:m TMX:m_a
STR:t 163000/s -- -16% -46% -84% -92% -93%
SU:t 196000/s 20% -- -35% -81% -90% -92%
STN:t 302000/s 85% 54% -- -70% -85% -88%
STM:t 1035120/s 535% 428% 242% -- -50% -59%
TMX:m 2110000/s 1195% 978% 598% 103% -- -16%
TMX:m_a 2540780/s 1460% 1198% 740% 145% 20% --
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
TMX:m_a: participant=Text::Minify::XS::minify_ascii
#table8#
{dataset=>"len100ws100"}
+--------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
| participant | rate (/s) | time (μs) | pct_faster_vs_slowest | pct_slower_vs_fastest | errors | samples |
+--------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
| String::Trim::NonRegex::trim | 30000 | 30 | 0.00% | 4113.73% | 5.3e-07 | 20 |
| String::Trim::Regex::trim | 159440 | 6.27194 | 358.43% | 819.16% | 0 | 20 |
| String::Util::trim | 188000 | 5.31 | 441.53% | 678.11% | 1.6e-09 | 22 |
| String::Trim::More::trim | 870000 | 1.1 | 2409.75% | 67.89% | 1.7e-09 | 20 |
| Text::Minify::XS::minify | 1052000 | 0.9505 | 2924.88% | 39.30% | 1.2e-11 | 20 |
| Text::Minify::XS::minify_ascii | 1470000 | 0.682 | 4113.73% | 0.00% | 2e-10 | 21 |
+--------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
Formatted as Benchmark.pm result:
Rate STN:t STR:t SU:t STM:t TMX:m TMX:m_a
STN:t 30000/s -- -79% -82% -96% -96% -97%
STR:t 159440/s 378% -- -15% -82% -84% -89%
SU:t 188000/s 464% 18% -- -79% -82% -87%
STM:t 870000/s 2627% 470% 382% -- -13% -38%
TMX:m 1052000/s 3056% 559% 458% 15% -- -28%
TMX:m_a 1470000/s 4298% 819% 678% 61% 39% --
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
TMX:m_a: participant=Text::Minify::XS::minify_ascii
#table9#
{dataset=>"len10ws1"}
+--------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
| participant | rate (/s) | time (ns) | pct_faster_vs_slowest | pct_slower_vs_fastest | errors | samples |
+--------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
| String::Util::trim | 850421 | 1175.89 | 0.00% | 687.42% | 0 | 20 |
| String::Trim::Regex::trim | 860740 | 1161.8 | 1.21% | 677.97% | 5.8e-12 | 25 |
| String::Trim::More::trim | 960000 | 1000 | 12.71% | 598.63% | 1.7e-09 | 20 |
| String::Trim::NonRegex::trim | 1000000 | 960 | 22.77% | 541.36% | 1.7e-09 | 20 |
| Text::Minify::XS::minify | 6200000 | 160 | 624.51% | 8.68% | 3.5e-10 | 29 |
| Text::Minify::XS::minify_ascii | 6696350 | 149.335 | 687.42% | 0.00% | 0 | 20 |
+--------------------------------+-----------+-----------+-----------------------+-----------------------+---------+---------+
Formatted as Benchmark.pm result:
Rate SU:t STR:t STM:t STN:t TMX:m TMX:m_a
SU:t 850421/s -- -1% -14% -18% -86% -87%
STR:t 860740/s 1% -- -13% -17% -86% -87%
STM:t 960000/s 17% 16% -- -4% -84% -85%
STN:t 1000000/s 22% 21% 4% -- -83% -84%
TMX:m 6200000/s 634% 626% 525% 500% -- -6%
TMX:m_a 6696350/s 687% 677% 569% 542% 7% --
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
TMX:m_a: participant=Text::Minify::XS::minify_ascii
Benchmark module startup overhead (bencher -m StringFunctions::Trim --module-startup
):
#table10#
+------------------------+-----------+-------------------+-----------------------+-----------------------+---------+---------+
| participant | time (ms) | mod_overhead_time | pct_faster_vs_slowest | pct_slower_vs_fastest | errors | samples |
+------------------------+-----------+-------------------+-----------------------+-----------------------+---------+---------+
| String::Util | 14.3 | 8.14 | 0.00% | 132.46% | 1.2e-05 | 20 |
| String::Trim::Regex | 12.2 | 6.04 | 17.49% | 97.85% | 1e-05 | 21 |
| Text::Minify::XS | 9.36 | 3.2 | 53.00% | 51.94% | 6.4e-06 | 21 |
| String::Trim::More | 9.07 | 2.91 | 58.00% | 47.13% | 9e-06 | 20 |
| String::Trim::NonRegex | 9 | 2.84 | 59.03% | 46.18% | 1e-05 | 20 |
| perl -e1 (baseline) | 6.16 | 0 | 132.46% | 0.00% | 5.4e-06 | 23 |
+------------------------+-----------+-------------------+-----------------------+-----------------------+---------+---------+
Formatted as Benchmark.pm result:
Rate S:U ST:R TM:X ST:M ST:N perl -e1 (baseline)
S:U 69.9/s -- -14% -34% -36% -37% -56%
ST:R 82.0/s 17% -- -23% -25% -26% -49%
TM:X 106.8/s 52% 30% -- -3% -3% -34%
ST:M 110.3/s 57% 34% 3% -- 0% -32%
ST:N 111.1/s 58% 35% 4% 0% -- -31%
perl -e1 (baseline) 162.3/s 132% 98% 51% 47% 46% --
Legends:
S:U: mod_overhead_time=8.14 participant=String::Util
ST:M: mod_overhead_time=2.91 participant=String::Trim::More
ST:N: mod_overhead_time=2.84 participant=String::Trim::NonRegex
ST:R: mod_overhead_time=6.04 participant=String::Trim::Regex
TM:X: mod_overhead_time=3.2 participant=Text::Minify::XS
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
.
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.