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 hamarb123 in #99596 #314

Open
EgorBot opened this issue Mar 12, 2025 · 0 comments
Open

EgorBot for hamarb123 in #99596 #314

EgorBot opened this issue Mar 12, 2025 · 0 comments

Comments

@EgorBot
Copy link
Owner

EgorBot commented Mar 12, 2025

Processing dotnet/runtime#99596 (comment) command:

Command

-arm -amd -mono

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

//ensure we haven't meaningfully regressed what we used ShuffleUnsafe for previously on mono

public unsafe class Benchmarks
{
    private byte* source = null;
    private char* dest = null;

    [Params(32, 64, 128, 256, 1024, 4096, 16384, 65536)]
    public int N;

    [GlobalSetup]
    public void Setup()
    {
        source = (byte*)NativeMemory.AlignedAlloc((uint)N, 4096);
        dest = (char*)NativeMemory.AlignedAlloc((uint)N * 4, 4096);
        new Random(42).NextBytes(new Span<byte>(source, N));
    }

    [GlobalCleanup]
    public void Teardown()
    {
        NativeMemory.AlignedFree(source);
        NativeMemory.AlignedFree(dest);
        source = null;
        dest = null;
    }

    [Benchmark]
    public (bool, int) TestTryToHexString()
    {
        var result = Convert.TryToHexString(new ReadOnlySpan<byte>(source, N), new Span<char>(dest, N * 2), out var written);
        return (result, written);
    }
}

(EgorBot will reply in 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

No branches or pull requests

1 participant