Skip to content

perf: match items in any order without copying the expected items - #1799

Merged
vbreuss merged 1 commit into
mainfrom
perf/item-matching-without-copies
Oct 11, 2026
Merged

vbreuss merged 1 commit into
mainfrom
perf/item-matching-without-copies

Conversation

@vbreuss

@vbreuss vbreuss commented Oct 11, 2026

Copy link
Copy Markdown
Member

The item matching that InAnyOrder() uses for values it cannot count copied the expected items, although the matcher already passes them as an array that is only read, and filled its assignments through Enumerable.Repeat(...).ToArray().

Benchmark (20 records) Before After
IsEqualTo(reversed).InAnyOrder() 3.948 µs / 3.63 KB 4.114 µs / 3.41 KB

The time differs within the error of about 0.35 µs.

The item matching that `InAnyOrder()` uses for values it cannot count copied the expected items, although the matcher already passes them as an array that is only read, and filled its assignments through `Enumerable.Repeat(...).ToArray()`.

| Benchmark (20 records) | Before | After |
|---|---:|---:|
| `IsEqualTo(reversed).InAnyOrder()` | 3.948 µs / 3.63 KB | 4.114 µs / 3.41 KB |

The time differs within the error of about 0.35 µs.
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

Test Results

     91 files       91 suites   1h 51m 54s ⏱️
 37 523 tests  37 523 ✅ 0 💤 0 ❌
217 902 runs  217 902 ✅ 0 💤 0 ❌

Results for commit bed42c0.

@vbreuss
vbreuss merged commit 37a229e into main Oct 11, 2026
16 checks passed
@vbreuss
vbreuss deleted the perf/item-matching-without-copies branch October 11, 2026 11:18
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.5 LTS (Noble Numbat)
AMD EPYC 7763 2.45GHz, 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-v3

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

Method Mean vs aweXpect Error StdDev Gen0 Gen1 Allocated vs aweXpect
Contains_aweXpect 593.3 ns 11.32 ns 10.04 ns 0.0429 - 728 B
Contains_FluentAssertions 361.0 ns -39% 2.74 ns 2.14 ns 0.0958 - 1608 B +121%
Contains_TUnit 416.3 ns -30% 8.40 ns 7.86 ns 0.0505 - 848 B +16%
Equivalency_aweXpect 13,293.4 ns 49.54 ns 38.68 ns 0.2289 - 4032 B
Equivalency_FluentAssertions 355,835.7 ns +2577% 1,411.96 ns 1,102.36 ns 35.1563 - 590292 B +14540%
Equivalency_TUnit 18,649.8 ns +40% 61.30 ns 57.34 ns 0.9155 - 15680 B +289%
EventTriggered_aweXpect 716.9 ns 3.36 ns 2.98 ns 0.1097 - 1840 B
EventTriggered_FluentAssertions 81,426.8 ns +11258% 1,008.62 ns 894.11 ns 0.2441 0.1221 5252 B +185%
Int_GreaterThan_aweXpect 149.9 ns 0.84 ns 0.74 ns 0.0324 - 544 B
Int_GreaterThan_FluentAssertions 233.3 ns +56% 2.46 ns 2.18 ns 0.0730 - 1224 B +125%
Int_GreaterThan_TUnit 237.7 ns +59% 6.52 ns 6.10 ns 0.0463 - 776 B +43%
ItemsCount_AtLeast_aweXpect 22,089.2 ns 183.12 ns 171.29 ns 0.5493 - 9592 B
ItemsCount_AtLeast_FluentAssertions 1,755.2 ns -92% 5.80 ns 4.53 ns 0.1183 - 2008 B -79%
ItemsCount_AtLeast_TUnit 1,681.8 ns -92% 5.74 ns 5.09 ns 0.0629 - 1064 B -89%
Multiple_aweXpect 1,017.1 ns 6.15 ns 5.75 ns 0.1278 - 2168 B
Multiple_FluentAssertions 1,794.6 ns +76% 14.98 ns 13.28 ns 0.4025 - 6744 B +211%
Multiple_TUnit 874.3 ns -14% 6.11 ns 5.42 ns 0.1335 - 2240 B +3%
Satisfies_aweXpect 205.9 ns 4.49 ns 4.20 ns 0.0348 - 584 B
Satisfies_FluentAssertions 31,962.3 ns +15419% 191.07 ns 169.38 ns 0.3052 0.2441 5614 B +861%
Satisfies_TUnit 264.2 ns +28% 4.33 ns 3.84 ns 0.0424 - 712 B +22%
String_aweXpect 295.8 ns 2.85 ns 2.53 ns 0.0362 - 608 B
String_FluentAssertions 530.3 ns +79% 4.84 ns 4.29 ns 0.1373 - 2304 B +279%
String_TUnit 346.7 ns +17% 4.76 ns 4.22 ns 0.0544 - 912 B +50%
StringArray_aweXpect 644.9 ns 2.35 ns 2.20 ns 0.0534 - 896 B
StringArray_FluentAssertions 1,278.5 ns +98% 11.92 ns 11.15 ns 0.2480 - 4152 B +363%
StringArray_TUnit 618.6 ns -4% 6.34 ns 5.30 ns 0.0753 - 1264 B +41%
StringArrayInAnyOrder_aweXpect 1,005.3 ns 4.12 ns 3.86 ns 0.0763 - 1304 B
StringArrayInAnyOrder_FluentAssertions 27,164.8 ns +2602% 109.51 ns 97.08 ns 1.9836 0.0610 33471 B +2467%
StringArrayInAnyOrder_TUnit 778.4 ns -23% 4.57 ns 4.06 ns 0.0839 - 1408 B +8%
Throws_aweXpect 13,597.7 ns 41.84 ns 34.94 ns 0.1373 - 2360 B
Throws_FluentAssertions 41,653.9 ns +206% 164.38 ns 153.76 ns 1.0986 - 18609 B +689%
Throws_TUnit 11,349.5 ns -17% 18.94 ns 16.79 ns 0.1068 - 1824 B -23%
ThrowsAsync_aweXpect 23,540.5 ns 142.49 ns 133.29 ns 0.1831 - 3064 B
ThrowsAsync_FluentAssertions 61,192.0 ns +160% 346.34 ns 323.96 ns 1.4038 - 23553 B +669%
ThrowsAsync_TUnit 22,342.6 ns -5% 48.27 ns 40.31 ns 0.1526 - 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