Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use existing Range vectorized fill in Enumerable.OrderBy #99538

Merged
merged 1 commit into from
Mar 12, 2024

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
111 checks passed
@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.

None yet

2 participants