XPerf
LanguagesC#Evidence

cs-regex-hot — Regex.IsMatch(pattern) in loop

Status: measured

Claim

Calling Regex.IsMatch(name, pattern) each iteration is slower than one RegexOptions.Compiled instance (~2.58× on .NET 10.0.13).

How measured

Runtime (this evidence file)

FieldValue
When2026-10-22 Asia/Shanghai (JSONL ts is UTC)
dotnet8.0.32
Median before (regex_ismatch_loop)4.1372 ms
Median after (compiled_regex)1.6045 ms
ratio before/after~2.58×

Lint mapping

csharpperf-lint cs-regex-hot: keep default severity.

Limits

  • Modest ratio; default stays hint; do not escalate to error on ~2.6× alone.

Constructor shape

new Regex every iteration versus one instance. Both sides still call IsMatch on id-2026. 2000 ops. Before 3.453 ms, after 0.483 ms, ratio 7.145. The matcher now flags new Regex( as well as the static Regex.IsMatch / Match calls. Default stays hint.