Skip to content

perf: copy arrays and lists at once in IsEquivalentTo - #1796

Merged
vbreuss merged 1 commit into
mainfrom
perf/equivalency-collection-copies
Oct 11, 2026
Merged

vbreuss merged 1 commit into
mainfrom
perf/equivalency-collection-copies

Conversation

@vbreuss

@vbreuss vbreuss commented Oct 11, 2026

Copy link
Copy Markdown
Member

Equivalency copied the items of both sequences with Cast<object?>().ToArray(), which enumerates a List<T> into a growing buffer and boxes value types through an iterator. An array of rank one and a List<T> know their count and now copy their items at once.

Benchmark Before After
IsEquivalentTo of an album with 17 tracks in a List<Track> 8.946 µs / 3.95 KB 7.807 µs / 3.01 KB

Equivalency copied the items of both sequences with `Cast<object?>().ToArray()`, which enumerates a `List<T>` into a growing buffer and boxes value types through an iterator. An array of rank one and a `List<T>` know their count and now copy their items at once.

| Benchmark | Before | After |
|---|---:|---:|
| `IsEquivalentTo` of an album with 17 tracks in a `List<Track>` | 8.946 µs / 3.95 KB | 7.807 µs / 3.01 KB |
| `IsEquivalentTo` of a `List<int>` with 100 items | 9.134 µs / 10.07 KB | 8.856 µs / 7.43 KB |
| `IsEquivalentTo` of a `string[]` with 100 items, for comparison | 5.383 µs / 2.74 KB | 5.176 µs / 2.74 KB |
@vbreuss vbreuss self-assigned this Oct 11, 2026
@vbreuss
vbreuss enabled auto-merge (squash) October 11, 2026 09:56
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

Test Results

     91 files       91 suites   2h 2m 17s ⏱️
 37 516 tests  37 516 ✅ 0 💤 0 ❌
217 902 runs  217 902 ✅ 0 💤 0 ❌

Results for commit a8e6e36.

@vbreuss
vbreuss merged commit 6046182 into main Oct 11, 2026
16 checks passed
@vbreuss
vbreuss deleted the perf/equivalency-collection-copies branch October 11, 2026 10:29
@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 604.6 ns 9.86 ns 9.22 ns 0.0429 - 728 B
Contains_FluentAssertions 359.2 ns -41% 2.35 ns 2.08 ns 0.0958 - 1608 B +121%
Contains_TUnit 378.3 ns -37% 1.80 ns 1.59 ns 0.0505 - 848 B +16%
Equivalency_aweXpect 13,050.3 ns 40.16 ns 35.60 ns 0.2289 - 4032 B
Equivalency_FluentAssertions 349,942.1 ns +2581% 1,818.22 ns 1,518.30 ns 35.1563 - 590292 B +14540%
Equivalency_TUnit 19,184.4 ns +47% 79.60 ns 66.47 ns 0.9155 - 15680 B +289%
EventTriggered_aweXpect 695.5 ns 2.37 ns 1.85 ns 0.1097 - 1840 B
EventTriggered_FluentAssertions 82,140.9 ns +11710% 1,481.14 ns 1,385.46 ns 0.2441 0.1221 5252 B +185%
Int_GreaterThan_aweXpect 140.2 ns 0.69 ns 0.58 ns 0.0324 - 544 B
Int_GreaterThan_FluentAssertions 232.3 ns +66% 1.87 ns 1.75 ns 0.0730 - 1224 B +125%
Int_GreaterThan_TUnit 238.0 ns +70% 1.96 ns 1.83 ns 0.0463 - 776 B +43%
ItemsCount_AtLeast_aweXpect 21,917.8 ns 109.84 ns 97.37 ns 0.5493 - 9592 B
ItemsCount_AtLeast_FluentAssertions 1,751.0 ns -92% 5.60 ns 5.23 ns 0.1183 - 2008 B -79%
ItemsCount_AtLeast_TUnit 1,662.9 ns -92% 6.51 ns 6.09 ns 0.0629 - 1064 B -89%
Multiple_aweXpect 1,030.3 ns 7.63 ns 7.13 ns 0.1278 - 2168 B
Multiple_FluentAssertions 1,770.0 ns +72% 7.17 ns 6.36 ns 0.4025 - 6744 B +211%
Multiple_TUnit 892.8 ns -13% 3.03 ns 2.83 ns 0.1335 - 2240 B +3%
Satisfies_aweXpect 174.7 ns 1.30 ns 1.21 ns 0.0348 - 584 B
Satisfies_FluentAssertions 31,004.1 ns +17644% 401.51 ns 375.57 ns 0.3052 0.2441 5614 B +861%
Satisfies_TUnit 244.6 ns +40% 1.51 ns 1.41 ns 0.0424 - 712 B +22%
String_aweXpect 264.4 ns 1.66 ns 1.56 ns 0.0362 - 608 B
String_FluentAssertions 505.5 ns +91% 2.03 ns 1.80 ns 0.1373 - 2304 B +279%
String_TUnit 315.9 ns +19% 2.09 ns 1.85 ns 0.0544 - 912 B +50%
StringArray_aweXpect 622.2 ns 2.24 ns 1.99 ns 0.0534 - 896 B
StringArray_FluentAssertions 1,261.0 ns +103% 6.38 ns 5.97 ns 0.2480 - 4152 B +363%
StringArray_TUnit 646.7 ns +4% 1.86 ns 1.45 ns 0.0753 - 1264 B +41%
StringArrayInAnyOrder_aweXpect 980.4 ns 3.33 ns 3.12 ns 0.0763 - 1304 B
StringArrayInAnyOrder_FluentAssertions 26,555.0 ns +2609% 85.16 ns 75.50 ns 1.9836 0.0610 33471 B +2467%
StringArrayInAnyOrder_TUnit 787.6 ns -20% 5.73 ns 5.08 ns 0.0839 - 1408 B +8%
Throws_aweXpect 13,447.6 ns 40.15 ns 33.52 ns 0.1373 - 2360 B
Throws_FluentAssertions 40,667.4 ns +202% 159.27 ns 148.98 ns 1.0986 - 18609 B +689%
Throws_TUnit 11,139.7 ns -17% 21.18 ns 19.81 ns 0.1068 - 1824 B -23%
ThrowsAsync_aweXpect 23,811.6 ns 48.19 ns 40.24 ns 0.1831 - 3064 B
ThrowsAsync_FluentAssertions 59,348.9 ns +149% 105.93 ns 88.46 ns 1.3428 - 23554 B +669%
ThrowsAsync_TUnit 22,461.1 ns -6% 25.46 ns 19.88 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