-
-
Notifications
You must be signed in to change notification settings - Fork 1k
BenchmarkDotNet doesn't display null parameter correctly #2449
Copy link
Copy link
Open
Description
BenchmarkDotNet version: 0.13.9
My benchmark code:
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
BenchmarkRunner.Run<NullableEqualsBenchmarks>();
public class NullableEqualsBenchmarks
{
[Params(1, 0, null)]
public int? Prop { get; set; }
[Benchmark]
public int CurrentLoweringNonDefault()
{
int? num = Prop;
int num2 = 42;
if ((num.GetValueOrDefault() == num2) & num.HasValue)
{
return 1;
}
return 0;
}
[Benchmark]
public int ProposedLoweringNonDefault()
{
if (Prop.GetValueOrDefault() == 42)
{
return 1;
}
return 0;
}
[Benchmark]
public int CurrentLoweringDefault()
{
int? num = Prop;
int num2 = 0;
if ((num.GetValueOrDefault() == num2) & num.HasValue)
{
return 1;
}
return 0;
}
[Benchmark]
public int ProposedLoweringDefault()
{
if (Prop.GetValueOrDefault(1) == 0)
{
return 1;
}
return 0;
}
}Result table after run:
| Method | Prop | Mean | Error | StdDev |
|---|---|---|---|---|
| CurrentLoweringNonDefault | ? | 0.4134 ns | 0.0025 ns | 0.0023 ns |
| ProposedLoweringNonDefault | ? | 0.2143 ns | 0.0095 ns | 0.0089 ns |
| CurrentLoweringDefault | ? | 0.4140 ns | 0.0004 ns | 0.0004 ns |
| ProposedLoweringDefault | ? | 0.2118 ns | 0.0089 ns | 0.0078 ns |
| CurrentLoweringNonDefault | 0 | 0.4051 ns | 0.0026 ns | 0.0024 ns |
| ProposedLoweringNonDefault | 0 | 0.2104 ns | 0.0070 ns | 0.0065 ns |
| CurrentLoweringDefault | 0 | 0.2134 ns | 0.0035 ns | 0.0030 ns |
| ProposedLoweringDefault | 0 | 0.0074 ns | 0.0015 ns | 0.0012 ns |
| CurrentLoweringNonDefault | 1 | 0.4160 ns | 0.0029 ns | 0.0027 ns |
| ProposedLoweringNonDefault | 1 | 0.2154 ns | 0.0063 ns | 0.0059 ns |
| CurrentLoweringDefault | 1 | 0.4141 ns | 0.0005 ns | 0.0004 ns |
| ProposedLoweringDefault | 1 | 0.2155 ns | 0.0064 ns | 0.0060 ns |
I would expect null to be displayed in Prop column instead of meaningless ?s
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Fields
Give feedbackNo fields configured for issues without a type.