Skip to content

Benchmarks for #116241 (EgorBo) #376

Open
@EgorBot

Description

@EgorBot

Processing dotnet/runtime#116241 (comment) command:

Command

-amd -arm

using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

BenchmarkSwitcher.FromAssembly(typeof(Benchmarks).Assembly).Run(args);

public class Benchmarks
{
    int class1 = 0;
    int class2 = 0;

    BaseClass b1 = new DerivedClass1();
    BaseClass b2 = new DerivedClass2();

    [Benchmark]
    public void Bench()
    {
        for (int i = 0; i < 10000; i++)
            Problem(i);
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    public void Problem(int i)
    {
        BaseClass b = i % 3 == 0 ? b1 : b2;
        if (b is DerivedClass1)
            class1++;
        else if (IsDerivedClass2(b))
            class2++;
    }

    public bool IsDerivedClass2(BaseClass b) => b is DerivedClass2;

    public class BaseClass { }
    public class DerivedClass1 : BaseClass { }
    public class DerivedClass2 : BaseClass { }
}

(EgorBot will reply in this issue)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions