Skip to content

EgorBot for AndyAyersMS in #109209 #140

@EgorBot

Description

@EgorBot

Processing dotnet/runtime#109209 (comment) command:

Command

-intel -arm64 -profiler --envvars DOTNET_JitDisasm:Foreach Count

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

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

public class Bench
{
    string[] s_ro_str_array = new string[512];

    [Benchmark]
    public int Foreach()
    {
        IEnumerable<string> e = s_ro_str_array;
        int sum = 0;
        foreach (string s in e) sum += s == null ? 0 : s.Length;
        return sum;
    }

    [Benchmark]
    public int Count() => CountInner(s_ro_str_array);

    [MethodImpl(MethodImplOptions.NoInlining)]
    int CountInner(ICollection<string> c) => c.Count;
}

(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