Skip to content

test: benchmark indexers on TUnit.Mocks - #997

Merged
vbreuss merged 2 commits into
mainfrom
test/tunit-mocks-indexer-benchmark
Nov 17, 2026
Merged

vbreuss merged 2 commits into
mainfrom
test/tunit-mocks-indexer-benchmark

Conversation

@vbreuss

@vbreuss vbreuss commented Nov 17, 2026

Copy link
Copy Markdown
Member

TUnit.Mocks supports indexers through the generated Item and SetItem extensions; the benchmark was disabled only because it used an indexer syntax that TUnit.Mocks does not provide.

TUnit.Mocks supports indexers through the generated Item and SetItem extensions; the benchmark was disabled only because it used an indexer syntax that TUnit.Mocks does not provide.
@vbreuss vbreuss self-assigned this Nov 17, 2026
Matches the other TUnit.Mocks benchmarks, which Sonar reports as inconsistent otherwise.
@vbreuss
vbreuss enabled auto-merge (squash) November 17, 2026 19:12
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

Test Results

    47 files  ±0      47 suites  ±0   1h 1m 15s ⏱️ + 1m 54s
 4 796 tests ±0   4 796 ✅ ±0  0 💤 ±0  0 ❌ ±0 
48 368 runs  ±0  48 368 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit 757aa9d. ± Comparison against base commit fffab2b.

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())
…

@vbreuss
vbreuss merged commit 2b9b9a0 into main Nov 17, 2026
23 checks passed
@vbreuss
vbreuss deleted the test/tunit-mocks-indexer-benchmark branch November 17, 2026 19:26
@github-actions

Copy link
Copy Markdown

🚀 Benchmark Results

Compared to main @​ fffab2ba: 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

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

Benchmark vs Imposter vs TUnitMocks
Callback 0.69× → 0.82× 🔹 -15% 1.68× → 1.88×
All benchmarks compared to main
Benchmark Time Memory vs Imposter vs TUnitMocks
Callback 223.9 ns → 253.8 ns (+13%) 952 B → 952 B 0.69× → 0.82× 🔹 -15% 1.68× → 1.88×
Raw results
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
AMD EPYC 7763 3.23GHz, 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 253.8 ns 4.13 ns 3.86 ns 1.00 952 B 1.00
Imposter 207.5 ns 2.57 ns 2.41 ns 0.82 616 B 0.65
TUnitMocks 476.6 ns 6.03 ns 5.34 ns 1.88 2056 B 2.16
Moq 103,850.6 ns 552.19 ns 461.10 ns 409.22 9056 B 9.51
NSubstitute 4,711.3 ns 21.44 ns 19.00 ns 18.56 7864 B 8.26
FakeItEasy 4,824.1 ns 37.68 ns 33.40 ns 19.01 6930 B 7.28

CompleteEventBenchmarks

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

Benchmark vs Imposter vs TUnitMocks
Event 0.82× → 0.92× 0.76× → 1.05× 🔹 -28%
All benchmarks compared to main
Benchmark Time Memory vs Imposter vs TUnitMocks
Event 199.7 ns → 236.5 ns (+18%) 864 B → 864 B 0.82× → 0.92× 0.76× → 1.05× 🔹 -28%
Raw results
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
INTEL XEON PLATINUM 8573C 3.00GHz, 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 236.5 ns 1.24 ns 1.03 ns 1.00 864 B 1.00
Imposter 217.3 ns 1.05 ns 0.88 ns 0.92 512 B 0.59
TUnitMocks 248.6 ns 0.86 ns 0.76 ns 1.05 1392 B 1.61
Moq 12,865.1 ns 135.82 ns 127.04 ns 54.40 12761 B 14.77
NSubstitute 5,244.2 ns 22.96 ns 19.18 ns 22.18 9192 B 10.64
FakeItEasy 153,632.2 ns 1,078.48 ns 956.04 ns 649.69 15579 B 18.03

CompleteIndexerBenchmarks

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

Benchmark vs Imposter vs TUnitMocks
Indexer (N=1000) 0.28× → 0.22× 🔸 +27% → 1.06×
All benchmarks compared to main
Benchmark Time Memory vs Imposter vs TUnitMocks
Indexer (N=1) 619.6 ns → 436.9 ns (-29%) 2,320 B → 2,320 B 0.40× → 0.43× → 1.05×
Indexer (N=10) 1.98 μs → 1.44 μs (-27%) 4,048 B → 4,048 B 0.31× → 0.30× → 1.13×
Indexer (N=1000) 154.44 μs → 122.16 μs (-21%) 194,129 B → 194,129 B 0.28× → 0.22× 🔸 +27% → 1.06×
Raw results
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
AMD EPYC 9V45 4.36GHz, 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 436.9 ns 13.17 ns 11.67 ns 1.00 2.27 KB 1.00
Imposter 1 187.0 ns 7.47 ns 6.99 ns 0.43 1.07 KB 0.47
TUnitMocks 1 460.8 ns 19.13 ns 16.96 ns 1.06 2.72 KB 1.20
Moq 1 64,897.3 ns 1,521.24 ns 1,270.30 ns 148.66 20.32 KB 8.97
NSubstitute 1 5,461.8 ns 124.27 ns 110.16 ns 12.51 12.78 KB 5.64
FakeItEasy 1 5,141.8 ns 118.21 ns 104.79 ns 11.78 13.27 KB 5.86
Mockolate 10 1,437.9 ns 37.48 ns 33.22 ns 1.00 3.95 KB 1.00
Imposter 10 438.0 ns 12.03 ns 11.25 ns 0.30 2.13 KB 0.54
TUnitMocks 10 1,628.0 ns 48.15 ns 45.03 ns 1.13 5.37 KB 1.36
Moq 10 66,386.6 ns 1,005.56 ns 891.40 ns 46.19 29.69 KB 7.51
NSubstitute 10 12,453.2 ns 283.87 ns 265.53 ns 8.67 25.58 KB 6.47
FakeItEasy 10 10,984.7 ns 323.86 ns 287.09 ns 7.64 32.47 KB 8.21
Mockolate 1000 122,157.7 ns 2,415.28 ns 2,259.26 ns 1.00 189.58 KB 1.00
Imposter 1000 26,745.9 ns 468.49 ns 391.21 ns 0.22 118.15 KB 0.62
TUnitMocks 1000 129,947.8 ns 4,091.04 ns 3,826.76 ns 1.06 293.67 KB 1.55
Moq 1000 478,422.0 ns 9,884.61 ns 9,246.07 ns 3.92 1006.45 KB 5.31
NSubstitute 1000 889,066.2 ns 30,923.61 ns 28,925.97 ns 7.28 1465.64 KB 7.73
FakeItEasy 1000 721,878.6 ns 18,444.62 ns 17,253.11 ns 5.91 2153 KB 11.36

CompleteMethodBenchmarks

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

Benchmark vs Imposter vs TUnitMocks
Method (N=1) 0.69× → 0.77× 1.74× → 2.13× 🔹 -18%
All benchmarks compared to main
Benchmark Time Memory vs Imposter vs TUnitMocks
Method (N=1) 250.5 ns → 203.4 ns (-19%) 1,040 B → 1,040 B 0.69× → 0.77× 1.74× → 2.13× 🔹 -18%
Method (N=10) 562.7 ns → 503.7 ns (-10%) 1,616 B → 1,616 B 0.62× → 0.62× 2.32× → 2.57×
Method (N=1000) 39.05 μs → 32.77 μs (-16%) 64,976 B → 64,976 B 0.56× → 0.53× 2.87× → 2.87×
Raw results
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
Intel Xeon 6975P-C 2.70GHz, 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 203.4 ns 8.56 ns 8.01 ns 1.00 1040 B 1.00
Imposter 1 156.3 ns 4.74 ns 4.43 ns 0.77 728 B 0.70
TUnitMocks 1 432.3 ns 7.84 ns 7.33 ns 2.13 2088 B 2.01
Moq 1 70,056.1 ns 547.47 ns 512.10 ns 344.92 15129 B 14.55
NSubstitute 1 4,366.5 ns 66.22 ns 58.70 ns 21.50 9320 B 8.96
FakeItEasy 1 3,661.4 ns 32.05 ns 29.98 ns 18.03 8151 B 7.84
Mockolate 10 503.7 ns 4.03 ns 3.77 ns 1.00 1616 B 1.00
Imposter 10 313.0 ns 5.39 ns 5.04 ns 0.62 1088 B 0.67
TUnitMocks 10 1,295.8 ns 6.75 ns 6.31 ns 2.57 3840 B 2.38
Moq 10 71,563.4 ns 179.99 ns 159.56 ns 142.09 19107 B 11.82
NSubstitute 10 6,128.9 ns 86.57 ns 80.98 ns 12.17 12344 B 7.64
FakeItEasy 10 5,880.7 ns 110.19 ns 97.68 ns 11.68 16391 B 10.14
Mockolate 1000 32,771.5 ns 219.08 ns 194.21 ns 1.00 64976 B 1.00
Imposter 1000 17,368.9 ns 425.24 ns 397.77 ns 0.53 40688 B 0.63
TUnitMocks 1000 94,099.8 ns 1,292.52 ns 1,209.02 ns 2.87 203585 B 3.13
Moq 1000 222,351.8 ns 3,529.58 ns 3,128.88 ns 6.79 432131 B 6.65
NSubstitute 1000 190,336.7 ns 1,537.02 ns 1,437.73 ns 5.81 378018 B 5.82
FakeItEasy 1000 265,097.4 ns 6,934.91 ns 6,486.92 ns 8.09 944522 B 14.54

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.56× 🟢 -24% 1.09× → 1.38× 🟢 -21%
All benchmarks compared to main
Benchmark Time Memory vs Imposter vs TUnitMocks
Property (N=1) 335.3 ns → 262.2 ns (-22%) 1,208 B → 1,208 B 0.43× → 0.56× 🟢 -24% 1.09× → 1.38× 🟢 -21%
Property (N=10) 856.0 ns → 682.8 ns (-20%) 2,216 B → 2,216 B 0.34× → 0.39× 1.64× → 1.88×
Property (N=1000) 56.00 μs → 49.86 μs (-11%) 113,096 B → 113,096 B 0.31× → 0.28× 2.08× → 1.92×
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 262.2 ns 7.90 ns 7.39 ns 1.00 1208 B 1.00
Imposter 1 147.0 ns 2.96 ns 2.76 ns 0.56 672 B 0.56
TUnitMocks 1 361.2 ns 5.99 ns 5.61 ns 1.38 1672 B 1.38
Moq 1 7,983.1 ns 138.17 ns 122.48 ns 30.47 10761 B 8.91
NSubstitute 1 5,589.7 ns 76.76 ns 71.80 ns 21.34 11688 B 9.68
FakeItEasy 1 5,797.8 ns 51.70 ns 48.36 ns 22.13 11436 B 9.47
Mockolate 10 682.8 ns 8.32 ns 7.38 ns 1.00 2216 B 1.00
Imposter 10 268.3 ns 4.50 ns 3.99 ns 0.39 960 B 0.43
TUnitMocks 10 1,285.3 ns 26.15 ns 24.46 ns 1.88 4024 B 1.82
Moq 10 12,706.1 ns 255.85 ns 239.33 ns 18.61 18697 B 8.44
NSubstitute 10 12,371.1 ns 355.59 ns 332.62 ns 18.12 21553 B 9.73
FakeItEasy 10 13,531.0 ns 313.55 ns 293.29 ns 19.82 31026 B 14.00
Mockolate 1000 49,861.4 ns 1,035.28 ns 968.40 ns 1.00 113096 B 1.00
Imposter 1000 13,829.2 ns 407.51 ns 381.18 ns 0.28 32641 B 0.29
TUnitMocks 1000 95,892.2 ns 783.46 ns 694.52 ns 1.92 242489 B 2.14
Moq 1000 552,663.1 ns 7,381.41 ns 6,904.58 ns 11.09 836734 B 7.40
NSubstitute 1000 789,051.7 ns 12,261.69 ns 11,469.59 ns 15.83 1139725 B 10.08
FakeItEasy 1000 998,091.9 ns 15,250.92 ns 13,519.55 ns 20.02 2194530 B 19.40

CompleteWorkflowBenchmarks

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

All benchmarks compared to main
Benchmark Time Memory vs Imposter vs TUnitMocks
Complete 1.26 μs → 1.76 μs (+40%) 4,232 B → 4,232 B 0.70× → 0.72× 1.98× → 2.10×
Raw results
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
INTEL XEON PLATINUM 8573C 3.00GHz, 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 1.761 μs 0.0079 μs 0.0070 μs 1.00 4.13 KB 1.00
Imposter 1.259 μs 0.0049 μs 0.0046 μs 0.72 3.17 KB 0.77
TUnitMocks 3.701 μs 0.0313 μs 0.0278 μs 2.10 10.3 KB 2.49
Moq 270.658 μs 4.1168 μs 3.6495 μs 153.72 46.2 KB 11.18
NSubstitute 25.578 μs 0.1141 μs 0.1067 μs 14.53 37.13 KB 8.98
FakeItEasy 20.880 μs 0.0427 μs 0.0357 μs 11.86 34.4 KB 8.32

MockCreationBenchmarks

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

All benchmarks compared to main
Benchmark Time Memory vs Imposter vs TUnitMocks
CreateMock 16.1 ns → 9.9 ns (-39%) 160 B → 160 B 5.57× → 5.99× 1.67× → 1.72×
Raw results
BenchmarkDotNet v0.15.8, Linux Ubuntu 26.04.1 LTS (Resolute Raccoon)
AMD EPYC 9V45 4.19GHz, 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 9.861 ns 0.3397 ns 0.3011 ns 1.00 160 B 1.00
Imposter 59.020 ns 0.6875 ns 0.5741 ns 5.99 504 B 3.15
TUnitMocks 16.991 ns 0.5030 ns 0.4705 ns 1.72 216 B 1.35
Moq 808.548 ns 12.3900 ns 11.5896 ns 82.07 2088 B 13.05
NSubstitute 1,185.024 ns 52.5613 ns 46.5942 ns 120.28 5032 B 31.45
FakeItEasy 1,022.408 ns 36.7628 ns 32.5893 ns 103.77 2755 B 17.22

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