dotnet / dotnet/BenchmarkDotNet

BenchmarkDotNet doesn't display `null` parameter correctly

Open
#2,449 1 comment 0 reactions 1 assignee Claimed by @YegorStepanov View on GitHub
Dominant language
C#
Stars
11.5k
Forks
1.1k
Avg merge
4d 11h
Merged PRs (30d)
11

Description

BenchmarkDotNet version: 0.13.9

My benchmark code:
```cs
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

BenchmarkRunner.Run();

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.