Skip to content

Benchmarks for #116150 (stephentoub) #367

@EgorBot

Description

@EgorBot

Processing dotnet/runtime#116150 (comment) command:

Command

-arm -amd -intel

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

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

[DisassemblyDiagnoser]
[MemoryDiagnoser(false)]
public class Bench
{
    [Benchmark]
    [ArgumentsSource(nameof(GetLists))]
    public int SumList(List<string> list)
    {
        int sum = 0;
        foreach (var item in list)
        {
            sum += Process(item);
        }
        return sum;
    }

    [Benchmark]
    [ArgumentsSource(nameof(GetLists))]
    public int SumEnumerable(IEnumerable<string> list)
    {
        int sum = 0;
        foreach (var item in list)
        {
            sum += Process(item);
        }
        return sum;
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    private static int Process(string item) => item.Length;

    public static IEnumerable<List<string>> GetLists() =>
        from count in new int[] { 1, 10, 1_000 }
        select Enumerable.Range(0, count).Select(i => i.ToString()).ToList();
}

(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