Skip to content

perf: count the items of Contains with a string synchronously - #1808

Merged
vbreuss merged 1 commit into
mainfrom
perf/contains-strings-synchronously
Oct 11, 2026
Merged

vbreuss merged 1 commit into
mainfrom
perf/contains-strings-synchronously

Conversation

@vbreuss

@vbreuss vbreuss commented Oct 11, 2026 •

Copy link
Copy Markdown
Member

Contains with a string awaited the comparison of every item, although the comparison without an option is ordinal and never needs to be awaited. Such an item is now matched synchronously, once the subject is known not to be a set whose comparer decides instead.

Measured in ABBA order (after, before, before, after), the mean of both runs:

Benchmark (List<string> of 17 titles) Before After
Contains of the first title 283.3 ns / 696 B 247.6 ns / 720 B

`Contains` with a string awaited the comparison of every item, although the comparison without an option is ordinal and never needs to be awaited. Such an item is now matched synchronously, once the subject is known not to be a set whose comparer decides instead.

Measured in ABBA order (after, before, before, after), the mean of both runs:

| Benchmark (`List<string>` of 17 titles) | Before | After |
|---|---:|---:|
| `Contains` of the first title | 283.3 ns / 696 B | 247.6 ns / 720 B |
| `Contains` of the seventh title | 380.3 ns / 696 B | 285.2 ns / 720 B |
| `Contains` of the last title | 580.3 ns / 696 B | 386.2 ns / 720 B |
@vbreuss vbreuss self-assigned this Oct 11, 2026
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

Test Results

     91 files       91 suites   1h 48m 17s ⏱️
 37 528 tests  37 528 ✅ 0 💤 0 ❌
217 902 runs  217 902 ✅ 0 💤 0 ❌

Results for commit 7198b71.

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.5 LTS (Noble Numbat)
Intel Xeon Platinum 8370C CPU 2.80GHz (Max: 2.79GHz), 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 449.9 ns 3.92 ns 3.66 ns 0.0286 - 720 B
Contains_FluentAssertions 450.1 ns ±0% 11.03 ns 10.32 ns 0.0639 - 1608 B +123%
Contains_TUnit 417.9 ns -7% 3.23 ns 3.02 ns 0.0334 - 848 B +18%
Equivalency_aweXpect 11,126.1 ns 18.14 ns 16.08 ns 0.1068 - 3040 B
Equivalency_FluentAssertions 329,211.8 ns +2859% 1,221.02 ns 1,142.14 ns 23.4375 - 590264 B +19317%
Equivalency_TUnit 19,510.4 ns +75% 52.90 ns 46.89 ns 0.6104 - 15680 B +416%
EventTriggered_aweXpect 775.9 ns 7.16 ns 6.70 ns 0.0734 - 1848 B
EventTriggered_FluentAssertions 60,865.4 ns +7745% 1,045.22 ns 872.80 ns 0.1831 0.1221 5254 B +184%
Int_GreaterThan_aweXpect 166.9 ns 1.78 ns 1.66 ns 0.0203 - 512 B
Int_GreaterThan_FluentAssertions 327.4 ns +96% 7.01 ns 6.21 ns 0.0486 - 1224 B +139%
Int_GreaterThan_TUnit 250.9 ns +50% 3.22 ns 2.69 ns 0.0305 - 776 B +52%
ItemsCount_AtLeast_aweXpect 18,137.0 ns 57.38 ns 53.67 ns 0.3662 - 9560 B
ItemsCount_AtLeast_FluentAssertions 2,153.7 ns -88% 9.90 ns 8.77 ns 0.0763 - 2008 B -79%
ItemsCount_AtLeast_TUnit 1,973.7 ns -89% 18.79 ns 17.58 ns 0.0420 - 1064 B -89%
Multiple_aweXpect 1,154.5 ns 13.76 ns 11.49 ns 0.0668 - 1720 B
Multiple_FluentAssertions 2,268.9 ns +97% 70.99 ns 62.93 ns 0.2670 - 6744 B +292%
Multiple_TUnit 974.6 ns -16% 6.91 ns 6.12 ns 0.0877 - 2240 B +30%
Satisfies_aweXpect 194.6 ns 1.06 ns 0.94 ns 0.0219 - 552 B
Satisfies_FluentAssertions 24,761.9 ns +12625% 185.65 ns 164.57 ns 0.2136 0.1831 5615 B +917%
Satisfies_TUnit 252.9 ns +30% 3.02 ns 2.83 ns 0.0281 - 712 B +29%
String_aweXpect 276.7 ns 1.33 ns 1.18 ns 0.0229 - 576 B
String_FluentAssertions 651.5 ns +135% 7.93 ns 7.41 ns 0.0916 - 2304 B +300%
String_TUnit 362.8 ns +31% 3.80 ns 3.37 ns 0.0362 - 912 B +58%
StringArray_aweXpect 625.5 ns 3.56 ns 3.33 ns 0.0343 - 864 B
StringArray_FluentAssertions 1,563.9 ns +150% 33.19 ns 31.05 ns 0.1640 - 4152 B +381%
StringArray_TUnit 684.2 ns +9% 6.22 ns 5.82 ns 0.0496 - 1264 B +46%
StringArrayInAnyOrder_aweXpect 656.7 ns 2.81 ns 2.49 ns 0.0362 - 912 B
StringArrayInAnyOrder_FluentAssertions 24,214.6 ns +3587% 139.07 ns 130.08 ns 1.3123 0.0305 33468 B +3570%
StringArrayInAnyOrder_TUnit 877.2 ns +34% 5.00 ns 4.44 ns 0.0553 - 1408 B +54%
Throws_aweXpect 11,437.4 ns 23.82 ns 21.11 ns 0.0610 - 1720 B
Throws_FluentAssertions 36,617.6 ns +220% 148.50 ns 131.64 ns 0.7324 - 18609 B +982%
Throws_TUnit 10,579.5 ns -8% 15.98 ns 13.35 ns 0.0610 - 1824 B +6%
ThrowsAsync_aweXpect 21,855.0 ns 54.62 ns 48.42 ns 0.0916 - 2640 B
ThrowsAsync_FluentAssertions 52,470.1 ns +140% 150.66 ns 133.55 ns 0.9155 - 23553 B +792%
ThrowsAsync_TUnit 20,829.2 ns -5% 31.83 ns 26.58 ns 0.0916 - 2920 B +11%

@vbreuss
vbreuss merged commit 45e98ef into main Oct 11, 2026
16 checks passed
@vbreuss
vbreuss deleted the perf/contains-strings-synchronously branch October 11, 2026 13:12
github-actions Bot added a commit that referenced this pull request Oct 11, 2026
…h a string synchronously (#1808) by Valentin Breuß
github-actions Bot added a commit that referenced this pull request Oct 11, 2026
…h a string synchronously (#1808) 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