Skip to content

test: benchmark members that are called 1000 times - #994

Merged
vbreuss merged 1 commit into
mainfrom
test/benchmarks-n-1000
Nov 17, 2026
Merged

vbreuss merged 1 commit into
mainfrom
test/benchmarks-n-1000

Conversation

@vbreuss

@vbreuss vbreuss commented Nov 17, 2026

Copy link
Copy Markdown
Member

N=1 and N=10 cannot show how the cost grows for a member that a test calls many times, which is where the design of the recording storage matters most.

The Method, Property and Indexer benchmarks get N=1000. The docs site groups the parameter values from the benchmark data, so N=1000 becomes selectable without a site change. Each of the three benchmark jobs runs about 50% longer (6 more cases each, 5 for Indexer).

N=1 and N=10 cannot show how the cost grows for a member that a test calls many times, which is where the recording storage design matters most.
@vbreuss vbreuss self-assigned this Nov 17, 2026
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

Test Results

    47 files  ±0      47 suites  ±0   57m 46s ⏱️ + 3m 47s
 4 808 tests ±0   4 808 ✅ ±0  0 💤 ±0  0 ❌ ±0 
48 500 runs  ±0  48 500 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit 4116b4b. ± Comparison against base commit 513e0f2.

This pull request removes 22 and adds 16 tests. Note that renamed tests count towards both.
 x-myHeader3: baz, True)
)
Mockolate.Internal.Tests.Internals.WildcardTests ‑ ShouldSupportMultilineStrings(
Mockolate.Internal.Tests.Internals.WildcardTests ‑ ShouldSupportMultilineStrings(
Mockolate.SourceGenerators.Tests.MethodSetupsTests ‑ WhenImplementingObjectMethods_ShouldUseSpecialInterfaces(bool Equals(object obj);
Mockolate.SourceGenerators.Tests.MethodSetupsTests ‑ WhenImplementingObjectMethods_ShouldUseSpecialInterfaces(bool Equals(object obj);
Mockolate.SourceGenerators.Tests.MethodSetupsTests ‑ WhenImplementingObjectMethods_ShouldUseSpecialInterfaces(string ToString();
Mockolate.SourceGenerators.Tests.MethodSetupsTests ‑ WhenImplementingObjectMethods_ShouldUseSpecialInterfaces(string ToString();
Mockolate.Tests.Web.ItExtensionsTests+IsHttpContentTests+WithHeadersTests ‑ ShouldVerifyStringHeaders(x-myHeader1 : foo
Mockolate.Tests.Web.ItExtensionsTests+IsHttpContentTests+WithHeadersTests ‑ ShouldVerifyStringHeaders(x-myHeader1 : foo
…
Mockolate.Internal.Tests.Internals.WildcardTests ‑ ShouldSupportMultilineStrings(
)
Mockolate.Internal.Tests.Internals.WildcardTests ‑ ShouldSupportMultilineStrings(
)
Mockolate.SourceGenerators.Tests.MethodSetupsTests ‑ WhenImplementingObjectMethods_ShouldUseSpecialInterfaces(bool Equals(object obj);
int GetHashCode();, public override bool Equals(object obj), public override int GetHashCode())
Mockolate.SourceGenerators.Tests.MethodSetupsTests ‑ WhenImplementingObjectMethods_ShouldUseSpecialInterfaces(bool Equals(object obj);
int GetHashCode();, public override bool Equals(object obj), public override int GetHashCode())
Mockolate.SourceGenerators.Tests.MethodSetupsTests ‑ WhenImplementingObjectMethods_ShouldUseSpecialInterfaces(string ToString();
bool Equals(object obj);, public override string ToString(), public override bool Equals(object obj))
Mockolate.SourceGenerators.Tests.MethodSetupsTests ‑ WhenImplementingObjectMethods_ShouldUseSpecialInterfaces(string ToString();
bool Equals(object? obj);
int GetHashCode();, public override string ToString(), public override int GetHashCode(), public override bool Equals(object? obj))
Mockolate.SourceGenerators.Tests.MethodSetupsTests ‑ WhenImplementingObjectMethods_ShouldUseSpecialInterfaces(string ToString();
int GetHashCode();, public override string ToString(), public override int GetHashCode())
Mockolate.SourceGenerators.Tests.MethodSetupsTests ‑ WhenImplementingObjectMethods_ShouldUseSpecialInterfaces(string ToString();
bool Equals(object obj);, public override string ToString(), public override bool Equals(object obj))
Mockolate.SourceGenerators.Tests.MethodSetupsTests ‑ WhenImplementingObjectMethods_ShouldUseSpecialInterfaces(string ToString();
bool Equals(object? obj);
int GetHashCode();, public override string ToString(), public override int GetHashCode(), public override bool Equals(object? obj))
Mockolate.SourceGenerators.Tests.MethodSetupsTests ‑ WhenImplementingObjectMethods_ShouldUseSpecialInterfaces(string ToString();
int GetHashCode();, public override string ToString(), public override int GetHashCode())
…

@github-actions

Copy link
Copy Markdown

🚀 Benchmark Results

Compared to main @​ 801acbe9: memory to the latest run, time to the median of the last 10 runs, as the runners differ in speed. A relative change marks when Mockolate gets more than 15% faster or slower relative to Imposter and TUnitMocks: 🔴 / 🟢 against both of them, 🔸 / 🔹 against only one.

CallbackBenchmarks

✅ No changes in memory or relative performance (1 benchmarks)

All benchmarks compared to main
Benchmark Time Memory vs Imposter vs TUnitMocks
Callback 261.2 ns → 279.3 ns (+7%) 1,552 B → 1,552 B 0.68× → 0.69× 1.62× → 1.56×
Raw results
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
AMD EPYC 7763 2.61GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 11.0.100
  [Host] : .NET 11.0.0 (11.0.0, 11.0.26.53018), X64 RyuJIT x86-64-v3

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

Callback Mean Error StdDev Ratio Allocated Alloc Ratio
Mockolate 279.3 ns 6.61 ns 6.18 ns 1.00 1552 B 1.00
Imposter 194.0 ns 0.94 ns 0.79 ns 0.69 616 B 0.40
TUnitMocks 435.4 ns 3.97 ns 3.52 ns 1.56 2056 B 1.32
Moq 102,954.0 ns 500.18 ns 467.87 ns 368.72 9056 B 5.84
NSubstitute 4,428.1 ns 17.68 ns 14.76 ns 15.86 7864 B 5.07
FakeItEasy 4,408.8 ns 14.96 ns 13.99 ns 15.79 6930 B 4.47

CompleteEventBenchmarks

✅ No changes in memory or relative performance (1 benchmarks)

All benchmarks compared to main
Benchmark Time Memory vs Imposter vs TUnitMocks
Event 210.1 ns → 163.6 ns (-22%) 1,000 B → 1,000 B 0.81× → 0.77× 0.75× → 0.76×
Raw results
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
AMD EPYC 9V45 3.94GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 11.0.100
  [Host] : .NET 11.0.0 (11.0.0, 11.0.26.53018), X64 RyuJIT x86-64-v4

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

Event Mean Error StdDev Ratio Allocated Alloc Ratio
Mockolate 163.6 ns 6.62 ns 6.19 ns 1.00 1000 B 1.00
Imposter 125.7 ns 3.31 ns 2.94 ns 0.77 512 B 0.51
TUnitMocks 124.7 ns 5.62 ns 4.98 ns 0.76 1392 B 1.39
Moq 8,413.8 ns 134.84 ns 119.54 ns 51.50 12760 B 12.76
NSubstitute 3,469.2 ns 76.57 ns 71.63 ns 21.23 9192 B 9.19
FakeItEasy 122,721.6 ns 2,310.79 ns 2,048.46 ns 751.16 15619 B 15.62

CompleteIndexerBenchmarks

✅ No changes in memory or relative performance (2 benchmarks)

New, without results on main: Indexer (N=1000)

All benchmarks compared to main
Benchmark Time Memory vs Imposter
Indexer (N=1) 619.6 ns → 558.1 ns (-10%) 2,576 B → 2,576 B 0.40× → 0.43×
Indexer (N=10) 1.98 μs → 1.87 μs (-5%) 4,248 B → 4,248 B 0.31× → 0.30×
Raw results
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
AMD EPYC 9V74 3.69GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 11.0.100
  [Host] : .NET 11.0.0 (11.0.0, 11.0.26.53018), X64 RyuJIT x86-64-v4

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

Indexer N Mean Error StdDev Ratio Allocated Alloc Ratio
Mockolate 1 558.1 ns 15.21 ns 14.23 ns 1.00 2.52 KB 1.00
Imposter 1 240.2 ns 1.77 ns 1.38 ns 0.43 1.07 KB 0.43
Moq 1 140,081.8 ns 892.10 ns 744.94 ns 251.13 20.43 KB 8.12
NSubstitute 1 7,341.2 ns 57.55 ns 51.02 ns 13.16 12.78 KB 5.08
FakeItEasy 1 7,015.6 ns 69.72 ns 61.80 ns 12.58 13.27 KB 5.28
Mockolate 10 1,871.9 ns 32.94 ns 30.81 ns 1.00 4.15 KB 1.00
Imposter 10 567.9 ns 5.21 ns 4.07 ns 0.30 2.13 KB 0.51
Moq 10 149,872.2 ns 732.26 ns 649.13 ns 80.08 29.8 KB 7.18
NSubstitute 10 18,593.4 ns 161.18 ns 150.76 ns 9.94 25.58 KB 6.17
FakeItEasy 10 16,394.5 ns 196.34 ns 183.66 ns 8.76 32.47 KB 7.83
Mockolate 1000 134,320.1 ns 985.99 ns 874.05 ns 1.00 135.09 KB 1.00
Imposter 1000 38,373.9 ns 594.17 ns 526.71 ns 0.29 118.15 KB 0.87
Moq 1000 767,362.4 ns 18,013.65 ns 16,849.98 ns 5.71 1006.57 KB 7.45
NSubstitute 1000 1,346,879.0 ns 40,714.10 ns 38,083.99 ns 10.03 1465.65 KB 10.85
FakeItEasy 1000 1,081,105.4 ns 21,817.88 ns 20,408.46 ns 8.05 2153 KB 15.94

CompleteMethodBenchmarks

✅ No changes in memory or relative performance (2 benchmarks)

New, without results on main: Method (N=1000)

All benchmarks compared to main
Benchmark Time Memory vs Imposter vs TUnitMocks
Method (N=1) 234.5 ns → 153.3 ns (-35%) 1,168 B → 1,168 B 0.68× → 0.70× 1.74× → 1.93×
Method (N=10) 485.4 ns → 464.9 ns (-4%) 1,744 B → 1,744 B 0.61× → 0.54× 2.31× → 2.23×
Raw results
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
AMD EPYC 9V45 4.20GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 11.0.100
  [Host] : .NET 11.0.0 (11.0.0, 11.0.26.53018), X64 RyuJIT x86-64-v4

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

Method N Mean Error StdDev Ratio Allocated Alloc Ratio
Mockolate 1 153.3 ns 3.93 ns 3.68 ns 1.00 1168 B 1.00
Imposter 1 106.9 ns 4.73 ns 4.43 ns 0.70 728 B 0.62
TUnitMocks 1 295.4 ns 10.61 ns 9.93 ns 1.93 2088 B 1.79
Moq 1 60,351.6 ns 1,355.41 ns 1,131.83 ns 393.87 14920 B 12.77
NSubstitute 1 3,309.8 ns 43.92 ns 38.93 ns 21.60 9264 B 7.93
FakeItEasy 1 3,181.8 ns 73.94 ns 65.55 ns 20.77 8160 B 6.99
Mockolate 10 464.9 ns 6.24 ns 5.21 ns 1.00 1744 B 1.00
Imposter 10 252.0 ns 6.69 ns 5.93 ns 0.54 1088 B 0.62
TUnitMocks 10 1,035.4 ns 33.01 ns 29.26 ns 2.23 3840 B 2.20
Moq 10 59,626.8 ns 674.74 ns 563.44 ns 128.28 18906 B 10.84
NSubstitute 10 4,603.6 ns 83.30 ns 65.04 ns 9.90 11784 B 6.76
FakeItEasy 10 4,878.4 ns 127.64 ns 113.15 ns 10.50 16394 B 9.40
Mockolate 1000 31,848.0 ns 424.19 ns 354.22 ns 1.00 37112 B 1.00
Imposter 1000 13,767.8 ns 262.11 ns 232.36 ns 0.43 40688 B 1.10
TUnitMocks 1000 78,131.5 ns 1,268.26 ns 1,124.28 ns 2.45 203585 B 5.49
Moq 1000 190,122.2 ns 6,242.33 ns 5,839.08 ns 5.97 431937 B 11.64
NSubstitute 1000 158,595.8 ns 5,855.15 ns 4,889.32 ns 4.98 322036 B 8.68
FakeItEasy 1000 225,681.0 ns 8,196.71 ns 7,266.17 ns 7.09 944380 B 25.45

CompletePropertyBenchmarks

Relative performance (how many times as long the other library takes as Mockolate, main → PR)

Benchmark vs Imposter vs TUnitMocks
Property (N=1) 0.43× → 0.44× 1.08× → 1.57× 🔹 -31%

New, without results on main: Property (N=1000)

All benchmarks compared to main
Benchmark Time Memory vs Imposter vs TUnitMocks
Property (N=1) 360.2 ns → 310.5 ns (-14%) 1,456 B → 1,456 B 0.43× → 0.44× 1.08× → 1.57× 🔹 -31%
Property (N=10) 836.9 ns → 737.5 ns (-12%) 2,224 B → 2,224 B 0.34× → 0.34× 1.62× → 1.61×
Raw results
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
AMD EPYC 9V74 3.69GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 11.0.100
  [Host] : .NET 11.0.0 (11.0.0, 11.0.26.53018), X64 RyuJIT x86-64-v4

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

Property N Mean Error StdDev Ratio Allocated Alloc Ratio
Mockolate 1 310.5 ns 6.89 ns 6.44 ns 1.00 1456 B 1.00
Imposter 1 137.3 ns 1.76 ns 1.56 ns 0.44 672 B 0.46
TUnitMocks 1 486.0 ns 12.07 ns 10.70 ns 1.57 1672 B 1.15
Moq 1 8,260.9 ns 167.40 ns 156.59 ns 26.62 10568 B 7.26
NSubstitute 1 5,555.3 ns 129.76 ns 108.36 ns 17.90 11688 B 8.03
FakeItEasy 1 5,339.1 ns 140.22 ns 124.30 ns 17.20 11196 B 7.69
Mockolate 10 737.5 ns 1.31 ns 1.10 ns 1.00 2224 B 1.00
Imposter 10 249.9 ns 1.93 ns 1.71 ns 0.34 960 B 0.43
TUnitMocks 10 1,190.9 ns 22.47 ns 21.01 ns 1.61 4024 B 1.81
Moq 10 12,087.7 ns 130.11 ns 121.70 ns 16.39 18505 B 8.32
NSubstitute 10 12,844.5 ns 179.79 ns 159.38 ns 17.42 21553 B 9.69
FakeItEasy 10 13,182.2 ns 149.11 ns 124.51 ns 17.87 30785 B 13.84
Mockolate 1000 47,983.6 ns 274.37 ns 256.65 ns 1.00 49152 B 1.00
Imposter 1000 12,974.8 ns 90.15 ns 79.92 ns 0.27 32641 B 0.66
TUnitMocks 1000 90,686.7 ns 368.14 ns 307.41 ns 1.89 242489 B 4.93
Moq 1000 504,555.2 ns 14,872.21 ns 13,911.47 ns 10.52 836541 B 17.02
NSubstitute 1000 825,722.6 ns 14,693.68 ns 13,744.48 ns 17.21 1139725 B 23.19
FakeItEasy 1000 949,754.2 ns 8,944.18 ns 8,366.39 ns 19.79 2194325 B 44.64

CompleteWorkflowBenchmarks

✅ No changes in memory or relative performance (1 benchmarks)

All benchmarks compared to main
Benchmark Time Memory vs Imposter vs TUnitMocks
Complete 1.12 μs → 677.5 ns (-40%) 4,064 B → 4,064 B 0.73× → 0.69× 2.02× → 1.86×
Raw results
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
AMD EPYC 9V45 4.53GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 11.0.100
  [Host] : .NET 11.0.0 (11.0.0, 11.0.26.53018), X64 RyuJIT x86-64-v4

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

Complete Mean Error StdDev Ratio Allocated Alloc Ratio
Mockolate 677.5 ns 8.21 ns 7.68 ns 1.00 3.97 KB 1.00
Imposter 470.4 ns 11.89 ns 11.13 ns 0.69 2.9 KB 0.73
TUnitMocks 1,257.8 ns 14.03 ns 12.44 ns 1.86 9.3 KB 2.34
Moq 93,986.2 ns 1,148.86 ns 1,018.44 ns 138.75 35.17 KB 8.86
NSubstitute 10,997.3 ns 147.32 ns 130.59 ns 16.23 35.32 KB 8.90
FakeItEasy 9,988.0 ns 336.25 ns 314.53 ns 14.74 27.87 KB 7.02

MockCreationBenchmarks

✅ No changes in memory or relative performance (1 benchmarks)

All benchmarks compared to main
Benchmark Time Memory vs Imposter vs TUnitMocks
CreateMock 17.5 ns → 14.1 ns (-19%) 160 B → 160 B 5.63× → 6.01× 1.68× → 1.68×
Raw results
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
AMD EPYC 9V74 3.69GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 11.0.100
  [Host] : .NET 11.0.0 (11.0.0, 11.0.26.53018), X64 RyuJIT x86-64-v4

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

CreateMock Mean Error StdDev Ratio Allocated Alloc Ratio
Mockolate 14.14 ns 0.276 ns 0.258 ns 1.00 160 B 1.00
Imposter 85.04 ns 2.497 ns 2.335 ns 6.01 504 B 3.15
TUnitMocks 23.71 ns 0.612 ns 0.572 ns 1.68 216 B 1.35
Moq 983.55 ns 4.652 ns 4.351 ns 69.57 2088 B 13.05
NSubstitute 1,390.88 ns 4.356 ns 3.401 ns 98.38 5032 B 31.45
FakeItEasy 1,141.11 ns 7.006 ns 5.850 ns 80.71 2755 B 17.22

@vbreuss
vbreuss merged commit 79ca04a into main Nov 17, 2026
23 checks passed
@vbreuss
vbreuss deleted the test/benchmarks-n-1000 branch November 17, 2026 17:16
github-actions Bot added a commit that referenced this pull request Nov 17, 2026
github-actions Bot added a commit that referenced this pull request Nov 17, 2026
@github-actions

Copy link
Copy Markdown

This is addressed in release v4.2.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