Command
-intel -arm64 -profiler --envvars DOTNET_JitDisasm:Foreach Count
```cs
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 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 c) => c.Count
}
```
The `Foreach` test should now devirtualize and stack allocate the enumerator (but not yet promote, needs #109209).
Processing https://github.com/dotnet/runtime/pull/109209#issuecomment-2440125268 command:
Command
-intel -arm64 -profiler --envvars DOTNET_JitDisasm:Foreach Count ```cs 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(EgorBot will reply in this issue)