Skip to content

perf: share parsed wildcard patterns between expectations - #1798

Merged
vbreuss merged 1 commit into
mainfrom
perf/cache-wildcard-regexes
Oct 11, 2026
Merged

vbreuss merged 1 commit into
mainfrom
perf/cache-wildcard-regexes

Conversation

@vbreuss

@vbreuss vbreuss commented Oct 11, 2026

Copy link
Copy Markdown
Member

A wildcard pattern was parsed into a new regex for every evaluation, both to match the value and to count its occurrences in Contains. It now uses the bounded cache of the parsed regexes.

Benchmark Before After
IsEqualTo("order-*").AsWildcard() 1.379 µs / 3.04 KB 414.0 ns / 792 B

A wildcard pattern was parsed into a new regex for every evaluation, both to match the value and to count its occurrences in `Contains`. It now uses the bounded cache of the parsed regexes.

| Benchmark | Before | After |
|---|---:|---:|
| `IsEqualTo("order-*").AsWildcard()` | 1.379 µs / 3.04 KB | 414.0 ns / 792 B |
| `IsEqualTo("ORDER-*").AsWildcard().IgnoringCase()` | 1.429 µs / 3.1 KB | 417.7 ns / 856 B |
| `Contains("1?3").AsWildcard()` | 2.490 µs / 4.72 KB | 548.4 ns / 1200 B |
@vbreuss vbreuss self-assigned this Oct 11, 2026
@vbreuss
vbreuss enabled auto-merge (squash) October 11, 2026 10:21
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

Test Results

     91 files       91 suites   2h 12m 19s ⏱️
 37 515 tests  37 515 ✅ 0 💤 0 ❌
217 902 runs  217 902 ✅ 0 💤 0 ❌

Results for commit fafc336.

@vbreuss
vbreuss merged commit 348b1c6 into main Oct 11, 2026
16 checks passed
@vbreuss
vbreuss deleted the perf/cache-wildcard-regexes branch October 11, 2026 10:51
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.5 LTS (Noble Numbat)
AMD EPYC 9V45 2.60GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.303
[Host] : .NET 8.0.31 (8.0.31, 8.0.3126.42015), X64 RyuJIT x86-64-v4

Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15
LaunchCount=1 WarmupCount=10

Method Mean vs aweXpect Error StdDev Gen0 Gen1 Allocated vs aweXpect
Contains_aweXpect 294.44 ns 6.613 ns 5.522 ns 0.0434 - 728 B
Contains_FluentAssertions 194.85 ns -34% 3.311 ns 2.765 ns 0.0961 0.0002 1608 B +121%
Contains_TUnit 203.20 ns -31% 6.845 ns 5.716 ns 0.0505 - 848 B +16%
Equivalency_aweXpect 6,426.21 ns 72.475 ns 60.520 ns 0.2365 - 4032 B
Equivalency_FluentAssertions 163,514.89 ns +2444% 1,201.997 ns 1,124.349 ns 35.1563 1.9531 590287 B +14540%
Equivalency_TUnit 9,118.39 ns +42% 105.239 ns 87.879 ns 0.9308 - 15680 B +289%
EventTriggered_aweXpect 352.07 ns 5.819 ns 5.443 ns 0.1097 - 1840 B
EventTriggered_FluentAssertions 29,093.91 ns +8164% 916.215 ns 857.028 ns 0.3052 0.2747 5256 B +186%
Int_GreaterThan_aweXpect 77.16 ns 1.911 ns 1.694 ns 0.0324 - 544 B
Int_GreaterThan_FluentAssertions 122.76 ns +59% 2.875 ns 2.548 ns 0.0730 - 1224 B +125%
Int_GreaterThan_TUnit 124.70 ns +62% 3.838 ns 3.590 ns 0.0463 - 776 B +43%
ItemsCount_AtLeast_aweXpect 12,677.13 ns 165.973 ns 138.595 ns 0.5646 - 9592 B
ItemsCount_AtLeast_FluentAssertions 842.85 ns -93% 7.443 ns 6.962 ns 0.1192 - 2008 B -79%
ItemsCount_AtLeast_TUnit 843.70 ns -93% 11.411 ns 10.116 ns 0.0629 - 1064 B -89%
Multiple_aweXpect 508.90 ns 9.848 ns 9.212 ns 0.1287 - 2168 B
Multiple_FluentAssertions 944.76 ns +86% 13.465 ns 11.936 ns 0.4025 - 6744 B +211%
Multiple_TUnit 431.33 ns -15% 4.965 ns 4.401 ns 0.1335 - 2240 B +3%
Satisfies_aweXpect 95.78 ns 1.815 ns 1.516 ns 0.0348 - 584 B
Satisfies_FluentAssertions 9,816.90 ns +10150% 425.963 ns 398.446 ns 0.3357 0.2899 5615 B +861%
Satisfies_TUnit 127.97 ns +34% 3.323 ns 3.109 ns 0.0424 - 712 B +22%
String_aweXpect 142.25 ns 2.761 ns 2.583 ns 0.0362 - 608 B
String_FluentAssertions 267.06 ns +88% 5.970 ns 5.584 ns 0.1373 - 2304 B +279%
String_TUnit 175.49 ns +23% 5.369 ns 4.759 ns 0.0544 - 912 B +50%
StringArray_aweXpect 299.73 ns 6.537 ns 5.459 ns 0.0534 - 896 B
StringArray_FluentAssertions 644.84 ns +115% 26.405 ns 22.049 ns 0.2480 - 4152 B +363%
StringArray_TUnit 327.45 ns +9% 6.210 ns 4.849 ns 0.0753 - 1264 B +41%
StringArrayInAnyOrder_aweXpect 500.96 ns 6.927 ns 5.784 ns 0.0772 - 1304 B
StringArrayInAnyOrder_FluentAssertions 9,411.25 ns +1779% 54.914 ns 51.367 ns 1.9989 0.0610 33471 B +2467%
StringArrayInAnyOrder_TUnit 392.20 ns -22% 8.235 ns 7.300 ns 0.0839 - 1408 B +8%
Throws_aweXpect 7,040.03 ns 166.818 ns 156.042 ns 0.1373 - 2360 B
Throws_FluentAssertions 17,799.75 ns +153% 181.626 ns 141.801 ns 1.0986 - 18609 B +689%
Throws_TUnit 6,103.79 ns -13% 122.862 ns 114.925 ns 0.1068 - 1824 B -23%
ThrowsAsync_aweXpect 12,205.29 ns 283.634 ns 265.311 ns 0.1831 - 3064 B
ThrowsAsync_FluentAssertions 26,280.92 ns +115% 558.055 ns 494.701 ns 1.4038 - 23553 B +669%
ThrowsAsync_TUnit 11,899.34 ns -3% 68.212 ns 60.468 ns 0.1678 - 2920 B -5%

@github-actions

Copy link
Copy Markdown
Contributor

This is addressed in release v3.1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

state: released The issue is released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant