NAME
bench-trie.pl - Compare corpus scanning across Perl builds
SYNOPSIS
perl Porting/bench-trie.pl \
--perl before=/path/to/before/perl --arg before=-I/path/to/core/lib \
--perl after=/path/to/after/perl --arg after=-I/path/to/core/lib \
--base before --cpu 2 --perf --out tmp/trie-corpus-run
perl Porting/bench-trie.pl --report tmp/trie-corpus-run
DESCRIPTION
Extends t/re/trie_bench.pl with a small reproducible corpus basket. It does not replace the existing short-string, compilation, large-alternation or Statistics::Regression benchmarks. It requires Perl 5.14 or later and core modules; installed Dumbbench::Stats is optional for outlier filtering.
The ten corpus families cover HTML tokens and rare attributes, prefixed HTML tag extraction, technical prose terminology, whole-word searches, Unicode folding, a variable watchlist extracted from real Perl source, whitespace-heavy source, and balanced/repetitive FASTA. All have ASCII-only native-byte, native-byte Latin-1 containing characters above 127, UTF-8-flagged Latin-1, and genuinely wide UTF-8 variants. DNA bases remain ASCII; FASTA descriptions carry the non-ASCII text. Motifs do not cross line breaks.
HTML and FASTA are deterministic generated fixtures. Prose comes from pod/perlintro.pod; variables and source come from Porting/bench.pl. Internationalized comments/text are added. native-ascii transliterates the accented fixture letters to single ASCII characters and replaces remaining non-ASCII characters with spaces, preserving offsets and the pattern dictionary. native retains characters in 128..255 with the UTF-8 flag off. These are mixed ASCII/Latin-1 texts, not texts consisting entirely of high bytes. Reports include non-ASCII and wide character counts. The native and UTF-8-Latin-1 pair has identical characters and patterns. Wide variants include Greek, CJK and emoji text. The run freezes UTF-8 fixture files, patterns, SHA-256 hashes, expected counts, offsets and lengths in .corpus/manifest.json. The fixture directory is hidden so source POD copied into the corpus is not mistaken for distribution documentation by the porting checks.
Preparation compares every match span with trie construction disabled. Each executable then validates its own complete span stream before timing. Measured scans accumulate match counts, offsets and lengths rather than running an empty match loop. Every sample checks those results. Corpus setup, decoding, pattern compilation and validation are outside the timed region.
Leading word boundaries and shared literal prefixes can disable AC. The tool records actual start-class traces for every Perl/case and includes those patterns as controls. Cases intended to exercise AC must actually select it. It does not silently remove a realistic boundary to improve the result. The folded watchlist uses Latin-1 terms against all four text encodings; mixing wide folded literals can create separate branches and prevent AC. Exact prose watchlists include wide terms as well.
Use --case=perl_variables,dna_motifs and --encoding=native-ascii,native to compare ASCII-only and high-byte-containing native subjects. --encoding=utf8-latin1,utf8-wide selects the UTF-8 subjects. --runs defaults to 12; --seconds to 0.05; --size to 32 KiB characters per fixture. The slowest executable calibrates one repetition count used by all executables. Faster builds may take less than the target time. Their order rotates between samples, with warmup and deterministic hash settings. Raw data is retained in samples.jsonl; the report keeps each workload separate. The default is a screening run comparing two builds. Add older release Perls when a historical comparison is needed. Confirm questionable cases with --case, --runs=20 and --seconds=0.2, rather than lengthening the whole basket. Use --size explicitly to study larger inputs or cache effects. The time target is approximate: a single scan is the minimum sample, and dense UTF-8 matches can become disproportionately expensive as input size grows. Calibration prints the expected slowest scan time before measuring each case. Child processes ignore inherited Perl library, startup-option, Unicode-I/O and TRIE_BENCH_MODE environment settings; supply explicit --arg options.
Perl executables and their extra arguments are explicit: repeat --arg label=argument as necessary. Give core-build library paths only to the corresponding builds; installed Perls should use their own libraries. Build versions, flags, threading and executable hashes are recorded. Historical build differences are context, not evidence isolating a compiler optimization. Measured executables must be unthreaded and nondebugging; the runner checks their configuration and compile options and rejects unsuitable builds.
--cpu optionally uses Linux taskset. --perf adds Linux perf user-mode counters; these cover the whole process, including setup. They are not the same measurement as the internal scan timer. Do not run wall-time and Cachegrind jobs concurrently on the measured CPU. Raw samples also retain task-clock milliseconds, context switches and CPU migrations to help assess interference from other activity.
DETAILED INSTRUCTION PROFILING
Every run emits cachegrind-benchmarks using the existing Porting/bench.pl format and the same frozen corpus. Its setup/loop subtraction isolates scanning from fixture loading and compilation. For example, select a few cases first:
perl Porting/bench.pl \
--benchfile=tmp/trie-corpus-run/cachegrind-benchmarks \
--tests='/perl_variables_native|prose_folded_utf8_wide/' \
--fields=Ir,Dr,Dw,COND,COND_m \
--write=tmp/trie-corpus-instructions.json \
/path/to/before/perl=before --args=-I/path/to/core/lib \
/path/to/after/perl=after --args=-I/path/to/core/lib
Read the saved instruction results using the existing --read, --fields, --norm and --sort options. Cachegrind counts explain work and simulated cache/branch behavior; they do not measure native CPU cycles.
Individual workers are also available for perf record/annotate:
./perl -Ilib t/re/trie_bench.pl --corpus run \
tmp/trie-corpus-run/.corpus perl_variables.native 100