Skip to content

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

@Smurf-IV

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();
    }

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