Skip to content

perf: speed up InAnyOrder() for collections of equal items - #1783

Merged
vbreuss merged 1 commit into
mainfrom
perf/any-order-expected-item-counts
Oct 11, 2026
Merged

vbreuss merged 1 commit into
mainfrom
perf/any-order-expected-item-counts

Conversation

@vbreuss

@vbreuss vbreuss commented Oct 11, 2026

Copy link
Copy Markdown
Member

When every item is found among the expected items, the any-order matcher still hashed each item twice, built a dictionary for only a few items and allocated the containers of the item matching, which the met expectation never uses. This made IsEqualTo(...).InAnyOrder() on three strings about 300 ns and 360 B slower than in order and slower than TUnit.

When every item is found among the expected items, the any-order matcher still hashed each item twice, built a dictionary for only a few items and allocated the containers of the item matching, which the met expectation never uses. This made `IsEqualTo(...).InAnyOrder()` on three strings about 300 ns and 360 B slower than in order and slower than TUnit.
@vbreuss vbreuss self-assigned this Oct 11, 2026
@vbreuss
vbreuss enabled auto-merge (squash) October 11, 2026 07:16
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

Test Results

     91 files  ±0       91 suites  ±0   1h 38m 41s ⏱️ - 25m 4s
 37 523 tests +2   37 523 ✅ +2  0 💤 ±0  0 ❌ ±0 
217 902 runs  ±0  217 902 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit 7f3d28f. ± Comparison against base commit 5cf6a80.

This pull request removes 4961 and adds 4891 tests. Note that renamed tests count towards both.

	
	    get;
	"a": 1
	await
	{
	}, 1)


, 2)

b, 2, False)
…
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(3cb25e1b-ade8-4854-b836-778c76b3f069)
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(5f99c28e-4c67-48b2-b5ec-0256da44cb2c)
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(6741ec87-8632-486f-b7f7-35f7cf057490)
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(6a9dcdb0-31b4-40ab-81c0-128b42f40d83)
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(86394d23-2f14-4ecc-b950-f3a907c80082)
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(acf23554-00b6-4b29-9a74-c7a514aac0d6)
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ InnerException_ShouldBeSet(b1fcf7ab-92d7-40b4-b0fe-aefa4cb24cbd)
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(180611af-2615-41bf-8657-1c6b47cb8573)
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(27e67461-8f75-4e87-b27e-264ce7fca357)
aweXpect.Core.Tests.Core.Exceptions.FailExceptionTests ‑ Message_ShouldBeSet(3ad1a9c8-d461-4dac-80c6-f58fe44f80a4)
…

@vbreuss
vbreuss merged commit 7790486 into main Oct 11, 2026
16 checks passed
@vbreuss
vbreuss deleted the perf/any-order-expected-item-counts branch October 11, 2026 07:39
@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
Bool_aweXpect 133.7 ns 3.97 ns 3.71 ns 0.0262 - 440 B
Bool_FluentAssertions 249.7 ns +87% 3.99 ns 3.33 ns 0.0567 - 952 B +116%
Bool_TUnit 209.1 ns +56% 4.14 ns 3.87 ns 0.0281 - 472 B +7%
Equivalency_aweXpect 110,540.5 ns 166.34 ns 138.90 ns 0.9766 - 16440 B
Equivalency_FluentAssertions 2,819,389.5 ns +2451% 21,250.56 ns 19,877.79 ns 289.0625 42.9688 4841651 B +29350%
Equivalency_TUnit 215,410.3 ns +95% 861.72 ns 806.06 ns 9.2773 0.4883 155992 B +849%
EventTriggered_aweXpect 731.3 ns 10.65 ns 9.97 ns 0.1097 - 1840 B
EventTriggered_FluentAssertions 82,856.5 ns +11230% 932.46 ns 778.65 ns 0.2441 0.1221 5252 B +185%
Int_GreaterThan_aweXpect 149.8 ns 1.81 ns 1.61 ns 0.0324 - 544 B
Int_GreaterThan_FluentAssertions 247.7 ns +65% 5.48 ns 5.13 ns 0.0730 - 1224 B +125%
Int_GreaterThan_TUnit 251.8 ns +68% 1.84 ns 1.72 ns 0.0463 - 776 B +43%
ItemsCount_AtLeast_aweXpect 319.8 ns 2.54 ns 2.38 ns 0.0377 - 632 B
ItemsCount_AtLeast_FluentAssertions 515.4 ns +61% 6.53 ns 6.11 ns 0.1192 - 2008 B +218%
ItemsCount_AtLeast_TUnit 419.5 ns +31% 2.09 ns 1.96 ns 0.0634 - 1064 B +68%
Satisfies_aweXpect 251.3 ns 3.04 ns 2.85 ns 0.0410 - 688 B
Satisfies_FluentAssertions 32,048.4 ns +12652% 394.68 ns 369.18 ns 0.3052 0.2441 5614 B +716%
Satisfies_TUnit 254.6 ns +1% 2.81 ns 2.34 ns 0.0424 - 712 B +3%
String_aweXpect 274.9 ns 2.78 ns 2.60 ns 0.0362 - 608 B
String_FluentAssertions 1,249.3 ns +354% 15.52 ns 14.52 ns 0.2346 - 3944 B +549%
String_TUnit 342.7 ns +25% 1.20 ns 1.12 ns 0.0544 - 912 B +50%
StringArray_aweXpect 716.7 ns 3.33 ns 2.95 ns 0.0534 - 896 B
StringArray_FluentAssertions 1,438.1 ns +101% 14.47 ns 12.83 ns 0.2480 - 4152 B +363%
StringArray_TUnit 674.9 ns -6% 5.42 ns 5.07 ns 0.0753 - 1264 B +41%
StringArrayInAnyOrder_aweXpect 1,072.9 ns 5.45 ns 5.09 ns 0.0763 - 1304 B
StringArrayInAnyOrder_FluentAssertions 27,975.3 ns +2508% 142.16 ns 132.98 ns 1.9836 0.0610 33471 B +2467%
StringArrayInAnyOrder_TUnit 822.0 ns -23% 6.05 ns 5.65 ns 0.0839 - 1408 B +8%

github-actions Bot added a commit that referenced this pull request Oct 11, 2026
…ctions of equal items (#1783) by Valentin Breuß
github-actions Bot added a commit that referenced this pull request Oct 11, 2026
…ctions of equal items (#1783) by Valentin Breuß
@vbreuss
vbreuss restored the perf/any-order-expected-item-counts branch October 11, 2026 08:24
@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