Skip to content

Refactor Array.Sort methods to use Span<T>.Sort - #121797

Closed
xtqqczze wants to merge 1 commit into
dotnet:mainfrom
xtqqczze:GH116109
Closed

xtqqczze wants to merge 1 commit into
dotnet:mainfrom
xtqqczze:GH116109

Conversation

@xtqqczze

Copy link
Copy Markdown
Contributor

These changes extend the benefits of #116109 to arrays.

@github-actions github-actions Bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Nov 19, 2025
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Nov 19, 2025
@xtqqczze

Copy link
Copy Markdown
Contributor Author

@EgorBot -intel

using BenchmarkDotNet.Attributes;

public class Bench
{
    int[] a = new int[10000];
    int[] b = new int[10000];
    MyComparer c = new MyComparer();

    [IterationSetup]
    public void IterationSetup() { for (int i = 0; i < a.Length; i++) a[i] = i; }

    [Benchmark]
    public void Sort() => Array.Sort(a, b, c);

    class MyComparer : IComparer<int>
    {
        public int Compare(int x, int y) => x-y;
    }   
}

@jkotas

jkotas commented Nov 19, 2025

Copy link
Copy Markdown
Member

These changes extend the benefits of #116109 to arrays.

Where do you see the benefits? #116109 was about avoiding boxing of the generic comparer. None of the methods that you are changing have a generic comparer.

@xtqqczze

Copy link
Copy Markdown
Contributor Author

None of the methods that you are changing have a generic comparer.

These methods take IComparer<T>?, no?

@xtqqczze

Copy link
Copy Markdown
Contributor Author

@MihuBot

@jkotas

jkotas commented Nov 19, 2025

Copy link
Copy Markdown
Member

These methods take IComparer?, no?

I meant TComparer argument for the generic instantiation, like Sort<T, TComparer>(....).

@xtqqczze xtqqczze closed this Nov 19, 2025
@xtqqczze

Copy link
Copy Markdown
Contributor Author

I see, I was confused by the fact #116109 did not affect the Array.Sort implementation, yet the benchmark in #116109 (comment) included it.

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

Labels

community-contribution Indicates that the PR has been added by a community member needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants