NAME

problem48-inline-html-escape-benchmark - compare Perl and Inline::C HTML escaping

PURPOSE

Compares the Perl reference with the production compiled XS backend and three Inline::C/XS implementations for replacing &, <, and >: a direct byte loop, a chunk-copy variant using memchr/memcpy, and a byte-indexed lookup table. It also measures the production dispatch rules over those candidate helpers. Workloads include dense escapes, sparse escapes whose first match is late, sparse escapes whose first match is at byte zero, and plain text. This tests whether dispatch based only on the first match position misses early-but-rare input. Each workload includes four sizes. It checks raw-byte, UTF-8, NUL, undef, empty, and quote-containing cases, including the UTF-8 flag, before reporting helper and full instruction-highlighting timings.

WHY IT EXISTS

Problem 48 evaluates native acceleration for repeated Dashboard routines. HTML escaping is a representative text operation; a native implementation is only a candidate until exact behavior and a meaningful speedup are measured. The lookup-table variant preserves evidence for a rejected algorithm. Production uses the direct XS loop for inputs up to 64 characters or when a long input has at least four escapes in its first 16 characters. Other escaped long inputs use the chunk-copy path, including early-but-rare escape strings.

WHEN TO USE

Use in the isolated Problem 48 Docker image with Inline::C, a C compiler, and Perl development headers. Every candidate is checked against the Perl result and complete highlighting output before timing. The benchmark does not claim that the helper is a whole-route bottleneck.

HOW TO USE

perl script/problem48-inline-html-escape-benchmark
perl script/problem48-inline-html-escape-benchmark --runs 9

The run count must be an odd positive integer. Four text sizes and four character distributions (dense, sparse, prefix-sparse, and plain) are tested. Small inputs are repeated within each sample to avoid timer-resolution zeros. Every timed result is compared with the Perl helper output and UTF-8 flag; the full editor-instruction highlighting result is compared byte-for-byte too. Inline compilation time is reported separately and excluded from per-call medians.

WHAT USES IT

Problem 48 research uses this benchmark to assess the Inline::C/XS approach, compare the shipped XS implementation with the Inline::C direct loop, and keep slower chunk-copy and lookup-table candidates reproducible. The dashboard and release process do not invoke it. With no compiled extension present, the production backend row explicitly reports the Perl fallback rather than claiming a native measurement.

EXAMPLES

d2 docker compose --service bench -f /tmp/d2-problem48-bench.yml --project-name dd-problem48-profile-next run --rm bench perl script/problem48-inline-html-escape-benchmark

d2 docker compose --service bench -f /tmp/d2-problem48-bench.yml --project-name dd-problem48-profile-next run --rm bench perl script/problem48-inline-html-escape-benchmark --runs 9