Skip to content

perf: evaluate the expectations of ThatAll and ThatAny without a task each - #1802

Merged
vbreuss merged 1 commit into
mainfrom
perf/combinations-without-tasks
Oct 11, 2026
Merged

vbreuss merged 1 commit into
mainfrom
perf/combinations-without-tasks

Conversation

@vbreuss

@vbreuss vbreuss commented Oct 11, 2026

Copy link
Copy Markdown
Member

The result of every combined expectation and of the combination itself was returned as a Task<Result>, which allocates even when the evaluation completes synchronously, because the result is a struct that cannot be cached.

Benchmark Before After
ThatAll of 3 met expectations (run 1) 551.8 ns / 2.08 KB 594.5 ns / 1.73 KB

The times differ within the noise between runs; the allocations are lower in both.

…task each

The result of every combined expectation and of the combination itself was returned as a `Task<Result>`, which allocates even when the evaluation completes synchronously, because the result is a struct that cannot be cached.

| Benchmark | Before | After |
|---|---:|---:|
| `ThatAll` of 3 met expectations (run 1) | 551.8 ns / 2.08 KB | 594.5 ns / 1.73 KB |
| `ThatAll` of 3 met expectations (run 2) | 570.9 ns / 2.08 KB | 581.1 ns / 1.73 KB |
| `ThatAny` of 2 expectations (run 1) | 535.6 ns / 1.48 KB | 480.0 ns / 1.23 KB |
| `ThatAny` of 2 expectations (run 2) | 461.7 ns / 1.48 KB | 490.7 ns / 1.23 KB |

The times differ within the noise between runs; the allocations are lower in both.
@vbreuss vbreuss self-assigned this Oct 11, 2026
@vbreuss
vbreuss enabled auto-merge (squash) October 11, 2026 10:22
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

Test Results

     91 files       91 suites   1h 57m 49s ⏱️
 37 521 tests  37 521 ✅ 0 💤 0 ❌
217 902 runs  217 902 ✅ 0 💤 0 ❌

Results for commit bd8b1d2.

@vbreuss
vbreuss merged commit cfbe54b into main Oct 11, 2026
16 checks passed
@vbreuss
vbreuss deleted the perf/combinations-without-tasks branch October 11, 2026 11:19
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.5 LTS (Noble Numbat)
Intel Xeon 6973P-C 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 414.4 ns 8.66 ns 8.10 ns 0.0086 - 728 B
Contains_FluentAssertions 381.4 ns -8% 15.38 ns 14.39 ns 0.0191 - 1608 B +121%
Contains_TUnit 370.6 ns -11% 11.08 ns 9.25 ns 0.0100 - 848 B +16%
Equivalency_aweXpect 8,155.2 ns 162.31 ns 143.89 ns 0.0458 - 4032 B
Equivalency_FluentAssertions 237,082.8 ns +2807% 2,630.44 ns 2,196.53 ns 6.8359 - 590225 B +14539%
Equivalency_TUnit 13,812.2 ns +69% 478.70 ns 424.36 ns 0.1831 - 15680 B +289%
EventTriggered_aweXpect 564.5 ns 11.16 ns 10.44 ns 0.0219 - 1840 B
EventTriggered_FluentAssertions 34,441.0 ns +6001% 912.35 ns 853.42 ns 0.0610 0.0305 5256 B +186%
Int_GreaterThan_aweXpect 130.7 ns 5.90 ns 5.23 ns 0.0064 - 544 B
Int_GreaterThan_FluentAssertions 277.1 ns +112% 9.78 ns 9.15 ns 0.0143 - 1224 B +125%
Int_GreaterThan_TUnit 188.3 ns +44% 5.91 ns 5.53 ns 0.0091 - 776 B +43%
ItemsCount_AtLeast_aweXpect 14,545.8 ns 374.64 ns 350.44 ns 0.1068 - 9592 B
ItemsCount_AtLeast_FluentAssertions 1,257.3 ns -91% 30.96 ns 27.45 ns 0.0229 - 2008 B -79%
ItemsCount_AtLeast_TUnit 1,119.5 ns -92% 27.48 ns 24.36 ns 0.0114 - 1064 B -89%
Multiple_aweXpect 788.6 ns 20.22 ns 18.91 ns 0.0257 - 2168 B
Multiple_FluentAssertions 1,782.1 ns +126% 63.14 ns 55.97 ns 0.0801 - 6744 B +211%
Multiple_TUnit 760.9 ns -4% 27.58 ns 25.80 ns 0.0267 - 2240 B +3%
Satisfies_aweXpect 164.0 ns 3.15 ns 2.46 ns 0.0069 - 584 B
Satisfies_FluentAssertions 15,365.6 ns +9268% 304.49 ns 284.82 ns 0.0610 0.0458 5614 B +861%
Satisfies_TUnit 196.1 ns +20% 4.36 ns 4.08 ns 0.0083 - 712 B +22%
String_aweXpect 216.4 ns 8.37 ns 7.83 ns 0.0072 - 608 B
String_FluentAssertions 561.5 ns +159% 8.62 ns 7.20 ns 0.0267 - 2304 B +279%
String_TUnit 306.5 ns +42% 6.22 ns 5.52 ns 0.0105 - 912 B +50%
StringArray_aweXpect 443.9 ns 8.53 ns 7.56 ns 0.0105 - 896 B
StringArray_FluentAssertions 1,233.4 ns +178% 36.44 ns 34.09 ns 0.0496 - 4152 B +363%
StringArray_TUnit 592.9 ns +34% 18.41 ns 17.22 ns 0.0143 - 1264 B +41%
StringArrayInAnyOrder_aweXpect 700.4 ns 20.11 ns 18.82 ns 0.0153 - 1304 B
StringArrayInAnyOrder_FluentAssertions 14,283.9 ns +1939% 493.86 ns 437.79 ns 0.3967 - 33465 B +2466%
StringArrayInAnyOrder_TUnit 670.9 ns -4% 25.83 ns 21.57 ns 0.0162 - 1408 B +8%
Throws_aweXpect 8,251.5 ns 205.70 ns 182.35 ns 0.0153 - 2360 B
Throws_FluentAssertions 25,515.3 ns +209% 509.48 ns 425.43 ns 0.2136 - 18608 B +688%
Throws_TUnit 7,222.0 ns -12% 178.01 ns 166.51 ns 0.0153 - 1824 B -23%
ThrowsAsync_aweXpect 14,491.5 ns 392.59 ns 367.23 ns 0.0305 - 3064 B
ThrowsAsync_FluentAssertions 34,663.6 ns +139% 265.30 ns 207.13 ns 0.2441 - 23553 B +669%
ThrowsAsync_TUnit 14,184.8 ns -2% 540.51 ns 505.60 ns 0.0305 - 2920 B -5%

@github-actions github-actions Bot added the state: released The issue is released label Oct 11, 2026
@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