Skip to content

perf: let the occurrences of a string be counted up to a maximum - #1815

Merged
vbreuss merged 1 commit into
mainfrom
perf/count-occurrences-up-to-a-maximum
Oct 11, 2026
Merged

vbreuss merged 1 commit into
mainfrom
perf/count-occurrences-up-to-a-maximum

Conversation

@vbreuss

@vbreuss vbreuss commented Oct 11, 2026

Copy link
Copy Markdown
Member

Contains(substring) only needs as many occurrences as its quantifier can decide, but CountOccurrences always searches the whole subject, which costs a full scan of a long string even when the first match already decides it.

This adds the overload on Core so that aweXpect can pass the decisive amount after the next Core release; the benchmark comparison follows with that consumer PR.

`Contains(substring)` only needs as many occurrences as its quantifier can decide, but `CountOccurrences` always searches the whole subject, which costs a full scan of a long string even when the first match already decides it.

This adds the overload on Core so that aweXpect can pass the decisive amount after the next Core release; the benchmark comparison follows with that consumer PR.
@vbreuss vbreuss self-assigned this Oct 11, 2026
@vbreuss
vbreuss merged commit 553d47f into main Oct 11, 2026
12 checks passed
@vbreuss
vbreuss deleted the perf/count-occurrences-up-to-a-maximum branch October 11, 2026 14:53
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.5 LTS (Noble Numbat)
AMD EPYC 9V74 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 364.8 ns 0.86 ns 0.72 ns 0.0429 - 720 B
Contains_FluentAssertions 338.0 ns -7% 2.41 ns 2.14 ns 0.0958 - 1608 B +123%
Contains_TUnit 358.4 ns -2% 0.78 ns 0.73 ns 0.0505 - 848 B +18%
Equivalency_aweXpect 9,247.7 ns 18.95 ns 16.80 ns 0.1678 - 3040 B
Equivalency_FluentAssertions 266,095.0 ns +2777% 1,436.93 ns 1,344.10 ns 35.1563 1.9531 590288 B +19317%
Equivalency_TUnit 14,681.8 ns +59% 57.41 ns 53.70 ns 0.9308 - 15680 B +416%
EventTriggered_aweXpect 578.9 ns 4.04 ns 3.78 ns 0.1097 - 1848 B
EventTriggered_FluentAssertions 51,918.6 ns +8868% 654.00 ns 546.12 ns 0.3052 0.2441 5256 B +184%
Int_GreaterThan_aweXpect 117.5 ns 1.03 ns 0.92 ns 0.0305 - 512 B
Int_GreaterThan_FluentAssertions 196.2 ns +67% 2.81 ns 2.63 ns 0.0730 - 1224 B +139%
Int_GreaterThan_TUnit 188.3 ns +60% 4.27 ns 3.99 ns 0.0463 - 776 B +52%
ItemsCount_AtLeast_aweXpect 215.2 ns 2.49 ns 2.33 ns 0.0358 - 600 B
ItemsCount_AtLeast_FluentAssertions 446.2 ns +107% 4.78 ns 4.47 ns 0.1197 - 2008 B +235%
ItemsCount_AtLeast_TUnit 316.1 ns +47% 8.05 ns 7.53 ns 0.0634 - 1064 B +77%
Multiple_aweXpect 956.9 ns 3.57 ns 3.34 ns 0.1011 - 1720 B
Multiple_FluentAssertions 1,501.7 ns +57% 42.94 ns 40.17 ns 0.4025 - 6744 B +292%
Multiple_TUnit 716.8 ns -25% 13.47 ns 12.60 ns 0.1335 - 2240 B +30%
Satisfies_aweXpect 137.3 ns 0.98 ns 0.91 ns 0.0329 - 552 B
Satisfies_FluentAssertions 14,994.8 ns +10819% 384.24 ns 359.42 ns 0.3357 0.2899 5615 B +917%
Satisfies_TUnit 179.5 ns +31% 0.58 ns 0.48 ns 0.0424 - 712 B +29%
String_aweXpect 208.3 ns 2.33 ns 2.06 ns 0.0343 - 576 B
String_FluentAssertions 420.8 ns +102% 8.59 ns 8.03 ns 0.1373 - 2304 B +300%
String_TUnit 266.5 ns +28% 3.45 ns 3.23 ns 0.0544 - 912 B +58%
StringArray_aweXpect 486.9 ns 3.76 ns 3.51 ns 0.0515 - 864 B
StringArray_FluentAssertions 1,073.8 ns +121% 14.96 ns 12.49 ns 0.2480 - 4152 B +381%
StringArray_TUnit 517.3 ns +6% 7.44 ns 6.96 ns 0.0753 - 1264 B +46%
StringArrayInAnyOrder_aweXpect 513.2 ns 3.19 ns 2.83 ns 0.0544 - 912 B
StringArrayInAnyOrder_FluentAssertions 16,054.5 ns +3028% 240.12 ns 224.60 ns 1.9836 0.0610 33471 B +3570%
StringArrayInAnyOrder_TUnit 602.0 ns +17% 12.29 ns 11.50 ns 0.0839 - 1408 B +54%
Throws_aweXpect 8,421.4 ns 15.27 ns 13.54 ns 0.0916 - 1720 B
Throws_FluentAssertions 26,995.1 ns +221% 78.98 ns 73.88 ns 1.0986 - 18609 B +982%
Throws_TUnit 8,130.9 ns -3% 15.32 ns 14.33 ns 0.1068 - 1824 B +6%
ThrowsAsync_aweXpect 16,406.1 ns 70.76 ns 66.19 ns 0.1526 - 2640 B
ThrowsAsync_FluentAssertions 38,319.8 ns +134% 316.61 ns 296.16 ns 1.4038 - 23553 B +792%
ThrowsAsync_TUnit 15,880.2 ns -3% 26.00 ns 24.32 ns 0.1526 - 2920 B +11%

github-actions Bot added a commit that referenced this pull request Oct 11, 2026
…e counted up to a maximum (#1815) by Valentin Breuß
github-actions Bot added a commit that referenced this pull request Oct 11, 2026
…e counted up to a maximum (#1815) by Valentin Breuß
@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