Skip to content

EgorBot for hamarb123 in #99596 #314

Open
@EgorBot

Description

@EgorBot

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)

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