Skip to content

[Bug] Span SumF is slower than a for loop over a span #21

Description

@Smurf-IV

image

    [Benchmark]
    public int IntSpanESumLinq()
    {
        int val = 0;
        foreach (int i in intArray.AsSpan())
        {
            val += i;
        }
        return val;
    }

    [Benchmark]
    public int IntSpanFSumLinq()
    {
        int val = 0;
        Span<int> span = intArray.AsSpan();
        for (int index = 0; index < span.Length; index++)
        {
            val += span[index];
        }

        return val;
    }

    [Benchmark]
    public int IntSpanSumFast()
    {
        return intArray.AsSpan().SumF();
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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