This looks like a runtime issue to me, but @AndreyAkinshin asked me to open an issue here for it.
I observed simply adding a [GlobalSetup] to a benchmark class causes default(object) to take more time than without it. I only observed this in net7.0 and net8.0, no other runtime, and not with default primitives.
public class WithGlobalSetup
{
[GlobalSetup] public void Setup() { }
[Benchmark] public object DefaultClass() => default;
}
public class WithoutGlobalSetup
{
[Benchmark] public object DefaultClass() => default;
}
| Type |
Method |
Mean |
Error |
StdDev |
Median |
| WithGlobalSetup |
DefaultClass |
0.8907 ns |
0.1133 ns |
0.2340 ns |
0.8152 ns |
| WithoutGlobalSetup |
DefaultClass |
0.0519 ns |
0.0560 ns |
0.0995 ns |
0.0000 ns |
OS is Windows 10 x64
CPU is AMD Phenom II X6 1055T @ 2.8 GHz
This looks like a runtime issue to me, but @AndreyAkinshin asked me to open an issue here for it.
I observed simply adding a
[GlobalSetup]to a benchmark class causesdefault(object)to take more time than without it. I only observed this in net7.0 and net8.0, no other runtime, and not with default primitives.OS is Windows 10 x64
CPU is AMD Phenom II X6 1055T @ 2.8 GHz