NAME
problem48-html-attribute-escape-benchmark - compare Perl and XS attribute escaping
PURPOSE
Measures the public HTML attribute escape helper against an independent pure-Perl reference that escapes body text and then runs separate double-quote and single-quote substitutions. It checks exact text and UTF-8-flag parity before timing. The reference deliberately calls the Perl body helper even when the XS backend is loaded, so the baseline cannot accidentally use production native code.
WHY IT EXISTS
Problem 48 uses Devel::NYTProf to identify repeated hot helpers and measures native changes instead of assuming they are faster. The production XS path escapes all five HTML-sensitive ASCII bytes in one pass. This command provides a repeatable function-level comparison on an ordinary navigation identifier and a quote-heavy value. It does not claim a whole-route or all-subroutine speedup.
WHEN TO USE
Run after changing _escape_html_attr, the native XSUB, or its dispatch contract. Run once without a built extension to measure the source-only Perl path, and once with the compiled extension in @INC to measure XS.
HOW TO USE
d2 docker compose exec dev perl script/problem48-html-attribute-escape-benchmark
d2 docker compose exec dev perl -I.p48-xs-build/blib/arch -I.p48-xs-build/blib/lib -Ilib script/problem48-html-attribute-escape-benchmark --iterations 100000 --runs 9
--iterations selects calls per sample and must be positive. --runs is an odd positive count so the median is a measured sample. Cases alternate which strategy runs first; a parity mismatch is fatal.
WHAT USES IT
This is an opt-in Problem 48 research command. Production code does not load it or its timing dependencies beyond core Time::HiRes.
EXAMPLES
d2 docker compose exec dev perl script/problem48-html-attribute-escape-benchmark --iterations 50000 --runs 7