Skip to content

perf: compare items synchronously in InAnyOrder().IgnoringDuplicates() - #1792

Merged
vbreuss merged 1 commit into
mainfrom
perf/any-order-ignoring-duplicates-allocations
Oct 11, 2026
Merged

vbreuss merged 1 commit into
mainfrom
perf/any-order-ignoring-duplicates-allocations

Conversation

@vbreuss

@vbreuss vbreuss commented Oct 11, 2026

Copy link
Copy Markdown
Member

Every comparison of an item with an expected item went through an async method with an exception filter, although the comparisons of values complete synchronously, and the dictionary of additional items was created even when no item was additional.

Benchmark Before After
IsEqualTo(expected).InAnyOrder().IgnoringDuplicates() (4 items, 3 expected) 1.106 µs / 1.54 KB 1.006 µs / 1.46 KB

@vbreuss vbreuss self-assigned this Oct 11, 2026
@vbreuss
vbreuss enabled auto-merge (squash) October 11, 2026 09:03
@vbreuss
vbreuss disabled auto-merge October 11, 2026 09:25
Every comparison of an item with an expected item went through an async method with an exception filter, although the comparisons of values complete synchronously, and the dictionary of additional items was created even when no item was additional.

| Benchmark | Before | After |
|---|---:|---:|
| `IsEqualTo(expected).InAnyOrder().IgnoringDuplicates()` (4 items, 3 expected) | 1.106 µs / 1.54 KB | 1.006 µs / 1.46 KB |
| Same with 200 items, 100 expected in reverse order | 247.9 µs / 17.06 KB | 147.0 µs / 16.98 KB |
@vbreuss
vbreuss force-pushed the perf/any-order-ignoring-duplicates-allocations branch from 2642527 to 53be7fe Compare October 11, 2026 09:33
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

Test Results

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

Results for commit 53be7fe.

@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 321.03 ns 15.430 ns 14.434 ns 0.0434 - 728 B
Contains_FluentAssertions 197.91 ns -38% 2.012 ns 1.783 ns 0.0961 0.0002 1608 B +121%
Contains_TUnit 200.89 ns -37% 2.659 ns 2.357 ns 0.0505 - 848 B +16%
Equivalency_aweXpect 6,580.32 ns 108.901 ns 90.937 ns 0.2365 - 4032 B
Equivalency_FluentAssertions 166,190.74 ns +2426% 5,175.484 ns 4,841.151 ns 35.1563 1.9531 590288 B +14540%
Equivalency_TUnit 9,578.63 ns +46% 108.502 ns 101.493 ns 0.9308 - 15680 B +289%
EventTriggered_aweXpect 369.78 ns 24.279 ns 21.522 ns 0.1097 - 1840 B
EventTriggered_FluentAssertions 28,055.83 ns +7487% 381.727 ns 318.759 ns 0.3052 0.2747 5256 B +186%
Int_GreaterThan_aweXpect 83.03 ns 3.415 ns 2.667 ns 0.0324 - 544 B
Int_GreaterThan_FluentAssertions 139.34 ns +68% 11.171 ns 10.450 ns 0.0730 - 1224 B +125%
Int_GreaterThan_TUnit 126.19 ns +52% 6.026 ns 5.637 ns 0.0463 - 776 B +43%
ItemsCount_AtLeast_aweXpect 12,720.90 ns 190.815 ns 178.489 ns 0.5646 - 9592 B
ItemsCount_AtLeast_FluentAssertions 960.73 ns -92% 36.238 ns 33.897 ns 0.1183 - 2008 B -79%
ItemsCount_AtLeast_TUnit 951.99 ns -93% 20.297 ns 18.986 ns 0.0629 - 1064 B -89%
Multiple_aweXpect 541.30 ns 13.832 ns 12.262 ns 0.1287 - 2168 B
Multiple_FluentAssertions 1,008.85 ns +86% 31.824 ns 28.211 ns 0.4025 - 6744 B +211%
Multiple_TUnit 448.95 ns -17% 6.894 ns 6.111 ns 0.1335 - 2240 B +3%
Satisfies_aweXpect 95.46 ns 1.406 ns 1.174 ns 0.0348 - 584 B
Satisfies_FluentAssertions 8,969.13 ns +9296% 262.927 ns 233.078 ns 0.3357 0.2899 5615 B +861%
Satisfies_TUnit 114.92 ns +20% 0.818 ns 0.638 ns 0.0424 - 712 B +22%
String_aweXpect 142.05 ns 2.229 ns 2.085 ns 0.0362 - 608 B
String_FluentAssertions 272.22 ns +92% 9.910 ns 9.270 ns 0.1373 - 2304 B +279%
String_TUnit 163.00 ns +15% 1.971 ns 1.843 ns 0.0544 - 912 B +50%
StringArray_aweXpect 314.08 ns 5.892 ns 5.511 ns 0.0534 - 896 B
StringArray_FluentAssertions 638.96 ns +103% 7.194 ns 6.730 ns 0.2480 - 4152 B +363%
StringArray_TUnit 306.16 ns -3% 4.605 ns 4.082 ns 0.0753 - 1264 B +41%
StringArrayInAnyOrder_aweXpect 509.18 ns 8.416 ns 7.460 ns 0.0772 - 1304 B
StringArrayInAnyOrder_FluentAssertions 9,578.70 ns +1781% 108.234 ns 101.242 ns 1.9989 0.0610 33471 B +2467%
StringArrayInAnyOrder_TUnit 378.97 ns -26% 5.751 ns 5.379 ns 0.0839 - 1408 B +8%
Throws_aweXpect 6,128.74 ns 59.807 ns 55.943 ns 0.1221 - 2144 B
Throws_FluentAssertions 17,941.31 ns +193% 223.077 ns 197.752 ns 1.0986 - 18609 B +768%
Throws_TUnit 5,987.16 ns -2% 78.637 ns 73.557 ns 0.1068 - 1824 B -15%
ThrowsAsync_aweXpect 11,927.64 ns 80.944 ns 75.715 ns 0.1831 - 3064 B
ThrowsAsync_FluentAssertions 25,976.61 ns +118% 148.008 ns 138.447 ns 1.4038 - 23553 B +669%
ThrowsAsync_TUnit 11,728.14 ns -2% 80.868 ns 67.529 ns 0.1678 - 2920 B -5%

@vbreuss
vbreuss merged commit 1c743b1 into main Oct 11, 2026
16 checks passed
@vbreuss
vbreuss deleted the perf/any-order-ignoring-duplicates-allocations branch October 11, 2026 10:19
@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