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

EgorBot for davidwrighton in #106843 #73

Open
EgorBot opened this issue Sep 4, 2024 · 3 comments
Open

EgorBot for davidwrighton in #106843 #73

EgorBot opened this issue Sep 4, 2024 · 3 comments

Comments

@EgorBot
Copy link
Owner

EgorBot commented Sep 4, 2024

Processing dotnet/runtime#106843 (comment) command:

Command

-intel -arm64

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

namespace VirtualDispatchChecks
{

    class _1
    {
        public virtual string Method() => "A";
    }

    class _2 : _1
    {
        public override string Method() => "B";
    }

    class _3 : _1
    {
        public override string Method() => "C";
    }

    class _4 : _1
    {
        public override string Method() => "D";
    }

    class _5 : _1
    {
        public override string Method() => "E";
    }
    class _6 : _1
    {
        public override string Method() => "F";
    }
    class _7 : _1
    {
        public override string Method() => "F";
    }

    class _8 : _1
    {
        public override string Method() => "F";
    }

    class _9 : _1
    {
        public override string Method() => "F";
    }

    class _10 : _1
    {
        public override string Method() => "F";
    }

    public class ResolveVirtualRepeatedly
    {
        static _1 _1 = new _1();
        static _1 _2 = new _2();
        static _1 _3 = new _3();
        static _1 _4 = new _4();
        static _1 _5 = new _5();
        static _1 _6 = new _6();
        static _1 _7 = new _7();
        static _1 _8 = new _8();
        static _1 _9 = new _9();
        static _1 _10 = new _10();
        [MethodImpl(MethodImplOptions.NoInlining)]
        static _1 GetA(int index)
        {
            switch (index % 10)
            {
                case 0:
                    return _10;
                case 1: return _1;
                case 2: return _2;
                case 3: return _3;
                case 4: return _4;
                case 5: return _5;
                case 6: return _6;
                case 7: return _7;
                case 8: return _8;
                case 9: return _9;
            }
            return null!;
        }

        [MethodImpl(MethodImplOptions.NoInlining)]
        static Func<string> GetAction(int index)
        {
            return GetA(index).Method;
        }

        [Benchmark]
        public void Get1Virtual()
        {
            GetAction(0);
        }

        [Benchmark]
        public void Get10Virtual()
        {
            GetAction(0);
            GetAction(1);
            GetAction(2);
            GetAction(3);
            GetAction(4);
            GetAction(5);
            GetAction(6);
            GetAction(7);
            GetAction(8);
            GetAction(9);
        }
    }
}

(EgorBot will reply in this issue)

@EgorBot
Copy link
Owner Author

EgorBot commented Sep 4, 2024

Benchmark results on Intel

BenchmarkDotNet v0.14.0, Ubuntu 22.04.4 LTS (Jammy Jellyfish)
Intel Xeon Platinum 8370C CPU 2.80GHz, 1 CPU, 8 logical and 4 physical cores
  Job-ECHFHB : .NET 10.0.0 (42.42.42.42424), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI
  Job-FJRIFJ : .NET 10.0.0 (42.42.42.42424), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI
Method Toolchain Mean Error Ratio
Get1Virtual Main 15.77 ns 0.256 ns 1.00
Get1Virtual PR 17.64 ns 0.217 ns 1.12
Get10Virtual Main 179.33 ns 1.929 ns 1.00
Get10Virtual PR 202.07 ns 1.185 ns 1.13

BDN_Artifacts.zip

@EgorBot
Copy link
Owner Author

EgorBot commented Sep 4, 2024

cc @davidwrighton

@EgorBot
Copy link
Owner Author

EgorBot commented Sep 4, 2024

Benchmark results on Ampere

BenchmarkDotNet v0.14.0, Ubuntu 22.04.4 LTS (Jammy Jellyfish)
Ampere
  Job-CLNVZZ : .NET 10.0.0 (42.42.42.42424), Arm64 RyuJIT AdvSIMD
  Job-HQMPJB : .NET 10.0.0 (42.42.42.42424), Arm64 RyuJIT AdvSIMD
Method Toolchain Mean Error Ratio
Get1Virtual Main 23.08 ns 0.335 ns 1.00
Get1Virtual PR 21.91 ns 0.169 ns 0.95
Get10Virtual Main 237.93 ns 1.455 ns 1.00
Get10Virtual PR 216.98 ns 1.825 ns 0.91

BDN_Artifacts.zip

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

No branches or pull requests

1 participant