Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BenchmarkDotNet doesn't display null parameter correctly #2449

Open
DoctorKrolic opened this issue Oct 19, 2023 · 1 comment · May be fixed by #2122
Open

BenchmarkDotNet doesn't display null parameter correctly #2449

DoctorKrolic opened this issue Oct 19, 2023 · 1 comment · May be fixed by #2122
Assignees

Comments

@DoctorKrolic
Copy link

DoctorKrolic commented Oct 19, 2023

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

@timcassell
Copy link
Collaborator

Should be fixed by #2122

@timcassell timcassell linked a pull request Oct 19, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants