Skip to content

perf: size the collections of an in-order IgnoringDuplicates() up front - #1803

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

vbreuss merged 1 commit into
mainfrom
perf/same-order-ignoring-duplicates-copies

Conversation

@vbreuss

@vbreuss vbreuss commented Oct 11, 2026

Copy link
Copy Markdown
Member

Matching a collection in order while ignoring duplicates numbered the subject and the expected items in collections that grew item by item, looked up every new item twice and built the set of placed items twice through LINQ. The collections are now sized for as many items as expected, an item is looked up once on .NET 8 and later, and the placed items are collected once.

Benchmark (20 strings) Before After
IsEqualTo(expected).IgnoringDuplicates() 6088.3 ns / 12992 B 4904 ns / 7632 B

…ront

Matching a collection in order while ignoring duplicates numbered the subject and the expected items in collections that grew item by item, looked up every new item twice and built the set of placed items twice through LINQ. The collections are now sized for as many items as expected, an item is looked up once on .NET 8 and later, and the placed items are collected once.

| Benchmark (20 strings) | Before | After |
|---|---:|---:|
| `IsEqualTo(expected).IgnoringDuplicates()` | 6088.3 ns / 12992 B | 4904 ns / 7632 B |
| `IsEqualTo(expected)`, for comparison | 985.4 ns / 1008 B | 1108 ns / 1008 B |
@vbreuss vbreuss self-assigned this Oct 11, 2026
@vbreuss
vbreuss enabled auto-merge (squash) October 11, 2026 10:35
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

Test Results

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

Results for commit 24e1813.

@vbreuss
vbreuss merged commit f041e2e into main Oct 11, 2026
16 checks passed
@vbreuss
vbreuss deleted the perf/same-order-ignoring-duplicates-copies branch October 11, 2026 11:23
@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 8573C 2.30GHz, 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 495.2 ns 7.19 ns 6.73 ns 0.0086 - 728 B
Contains_FluentAssertions 444.6 ns -10% 5.07 ns 4.23 ns 0.0191 - 1608 B +121%
Contains_TUnit 394.7 ns -20% 1.83 ns 1.62 ns 0.0100 - 848 B +16%
Equivalency_aweXpect 10,235.9 ns 39.20 ns 36.67 ns 0.0458 - 4032 B
Equivalency_FluentAssertions 287,376.3 ns +2708% 724.79 ns 677.97 ns 6.8359 - 590224 B +14538%
Equivalency_TUnit 16,972.5 ns +66% 80.41 ns 67.14 ns 0.1831 - 15680 B +289%
EventTriggered_aweXpect 714.9 ns 1.93 ns 1.71 ns 0.0219 - 1840 B
EventTriggered_FluentAssertions 32,498.0 ns +4446% 124.27 ns 116.24 ns 0.0610 - 5256 B +186%
Int_GreaterThan_aweXpect 168.3 ns 0.91 ns 0.85 ns 0.0064 - 544 B
Int_GreaterThan_FluentAssertions 299.9 ns +78% 3.34 ns 3.13 ns 0.0143 - 1224 B +125%
Int_GreaterThan_TUnit 226.3 ns +34% 1.46 ns 1.36 ns 0.0091 - 776 B +43%
ItemsCount_AtLeast_aweXpect 18,110.1 ns 39.23 ns 36.70 ns 0.0916 - 9592 B
ItemsCount_AtLeast_FluentAssertions 2,172.1 ns -88% 6.90 ns 6.46 ns 0.0229 - 2008 B -79%
ItemsCount_AtLeast_TUnit 2,319.3 ns -87% 14.79 ns 13.83 ns 0.0114 - 1064 B -89%
Multiple_aweXpect 971.5 ns 3.32 ns 2.95 ns 0.0248 - 2168 B
Multiple_FluentAssertions 2,115.1 ns +118% 12.97 ns 12.13 ns 0.0801 - 6744 B +211%
Multiple_TUnit 887.0 ns -9% 4.45 ns 4.16 ns 0.0267 - 2240 B +3%
Satisfies_aweXpect 203.9 ns 0.69 ns 0.64 ns 0.0069 - 584 B
Satisfies_FluentAssertions 15,829.0 ns +7662% 110.16 ns 103.05 ns 0.0610 0.0305 5614 B +861%
Satisfies_TUnit 227.3 ns +11% 0.52 ns 0.49 ns 0.0083 - 712 B +22%
String_aweXpect 268.9 ns 0.73 ns 0.68 ns 0.0072 - 608 B
String_FluentAssertions 640.6 ns +138% 5.86 ns 5.48 ns 0.0267 - 2304 B +279%
String_TUnit 337.9 ns +26% 1.29 ns 1.15 ns 0.0105 - 912 B +50%
StringArray_aweXpect 572.3 ns 1.78 ns 1.67 ns 0.0105 - 896 B
StringArray_FluentAssertions 1,449.9 ns +153% 2.79 ns 2.61 ns 0.0496 - 4152 B +363%
StringArray_TUnit 612.3 ns +7% 1.67 ns 1.56 ns 0.0143 - 1264 B +41%
StringArrayInAnyOrder_aweXpect 870.8 ns 3.11 ns 2.91 ns 0.0153 - 1304 B
StringArrayInAnyOrder_FluentAssertions 17,249.7 ns +1881% 47.80 ns 44.71 ns 0.3967 - 33465 B +2466%
StringArrayInAnyOrder_TUnit 727.4 ns -16% 2.08 ns 1.84 ns 0.0162 - 1408 B +8%
Throws_aweXpect 10,740.8 ns 40.27 ns 33.63 ns 0.0153 - 2360 B
Throws_FluentAssertions 30,912.1 ns +188% 86.38 ns 80.80 ns 0.1831 - 18609 B +689%
Throws_TUnit 9,249.8 ns -14% 30.51 ns 28.54 ns 0.0153 - 1824 B -23%
ThrowsAsync_aweXpect 18,755.0 ns 42.63 ns 37.79 ns 0.0305 - 3064 B
ThrowsAsync_FluentAssertions 44,212.9 ns +136% 65.71 ns 54.87 ns 0.2441 - 23553 B +669%
ThrowsAsync_TUnit 18,864.0 ns +1% 24.22 ns 20.22 ns 0.0305 - 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