Skip to content

Conversation

@EgorBo
Copy link
Member

@EgorBo EgorBo commented Oct 5, 2024

Just a perf test

@ghost ghost added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Oct 5, 2024
@EgorBo
Copy link
Member Author

EgorBo commented Oct 5, 2024

@EgorBot -intel -arm64 -profiler

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

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

public class Benchmarks
{
    static bool[] _values = Enumerable.Range(0, 256).Select(i => i % 2 == 0).ToArray();
    static char[] _output = new char[4096];

    [Benchmark]
    public void WriteBools()
    {
        Span<char> output = _output;
        foreach (var value in _values)
        {
            if (value.TryFormat(output, out int written))
                output = output.Slice(written);
            else
                throw new InvalidOperationException();
        }

        Consume(output);
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    void Consume(Span<char> _){}
}

@EgorBo
Copy link
Member Author

EgorBo commented Oct 5, 2024

To be fair, I expected this PR to slightly regress performance since we currently generate a bit suboptimal codegen for Memmove unrolling in JIT against constant data, but it actually improves...😐

@EgorBo
Copy link
Member Author

EgorBo commented Oct 5, 2024

@EgorBot -intel -arm64 -profiler

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

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

public class Benchmarks
{
    static bool[] _values = Enumerable.Range(0, 256).Select(i => i % 2 == 0).ToArray();
    static char[] _output = new char[4096];

    [Benchmark]
    public void WriteBools()
    {
        Span<char> output = _output;
        foreach (var value in _values)
        {
            if (value.TryFormat(output, out int written))
                output = output.Slice(written);
            else
                throw new InvalidOperationException();
        }

        Consume(output);
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    void Consume(Span<char> _){}
}

@EgorBo
Copy link
Member Author

EgorBo commented Oct 5, 2024

@EgorBot -mono -intel -arm64

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

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

public class Benchmarks
{
    static bool[] _values = Enumerable.Range(0, 256).Select(i => i % 2 == 0).ToArray();
    static char[] _output = new char[4096];

    [Benchmark]
    public void WriteBools()
    {
        Span<char> output = _output;
        foreach (var value in _values)
        {
            if (value.TryFormat(output, out int written))
                output = output.Slice(written);
            else
                throw new InvalidOperationException();
        }

        Consume(output);
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    void Consume(Span<char> _){}
}

@xtqqczze
Copy link
Contributor

xtqqczze commented Oct 5, 2024

@MihuBot

@EgorBo
Copy link
Member Author

EgorBo commented Oct 5, 2024

@EgorBot -mono -intel -arm64 --envvars MONO_ENV_OPTIONS:--interpreter

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

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

public class Benchmarks
{
    static bool[] _values = Enumerable.Range(0, 256).Select(i => i % 2 == 0).ToArray();
    static char[] _output = new char[4096];

    [Benchmark]
    public void WriteBools()
    {
        Span<char> output = _output;
        foreach (var value in _values)
        {
            if (value.TryFormat(output, out int written))
                output = output.Slice(written);
            else
                throw new InvalidOperationException();
        }

        Consume(output);
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    void Consume(Span<char> _){}
}

xtqqczze added a commit to xtqqczze/dotnet-runtime that referenced this pull request Oct 6, 2024
xtqqczze added a commit to xtqqczze/dotnet-runtime that referenced this pull request Oct 6, 2024
xtqqczze added a commit to xtqqczze/dotnet-runtime that referenced this pull request Oct 8, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Nov 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants