Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

stephentoub
Copy link
Member

We already have a method that vectorizes the fill in Enumerable.Range. We can use the same helper in OrderBy when filling the integer map used to enable stability.

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

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

[HideColumns("Job", "Error", "StdDev", "Median", "RatioSD")]
public class Tests
{
    private IEnumerable<int> _data;

    [Params(4, 40, 400)]
    public int Count { get; set; }

    [GlobalSetup]
    public void Setup() => _data = Enumerable.Range(0, Count).ToArray();

    [Benchmark]
    public int OrderBy()
    {
        int sum = 0;
        foreach (int value in _data.OrderBy(i => i))
            sum += value;
        return sum;
    }
}
Method Toolchain Count Mean Ratio
OrderBy \main\corerun.exe 4 98.84 ns 1.00
OrderBy \pr\corerun.exe 4 99.85 ns 1.01
OrderBy \main\corerun.exe 40 515.74 ns 1.00
OrderBy \pr\corerun.exe 40 490.10 ns 0.95
OrderBy \main\corerun.exe 400 6,716.60 ns 1.00
OrderBy \pr\corerun.exe 400 6,200.64 ns 0.93

We already have a method that vectorizes the fill in Enumerable.Range. We can use the same helper in OrderBy when filling the integer map used to enable stability.
@stephentoub stephentoub merged commit 342bc7e into dotnet:main Mar 12, 2024
@stephentoub stephentoub deleted the orderbyfill branch March 12, 2024 14:15
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Linq tenet-performance Performance related issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants