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

Skip to content

Conversation

stephentoub
Copy link
Member

We already special-case length 0. That can trivially be extended to length 1.

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

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

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

    [Params(1)]
    public int Count { get; set; }

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

    [Benchmark]
    public string[] OrderArray() => _data.Order().ToArray();

    [Benchmark]
    public List<string> OrderList() => _data.Order().ToList();
}
Method Toolchain Count Mean Ratio Allocated Alloc Ratio
OrderArray \main\corerun.exe 1 85.30 ns 1.00 336 B 1.00
OrderArray \pr\corerun.exe 1 33.53 ns 0.39 120 B 0.36
OrderList \main\corerun.exe 1 91.46 ns 1.00 392 B 1.00
OrderList \pr\corerun.exe 1 42.60 ns 0.47 184 B 0.47

We already special-case length 0. That can trivially be extended to length 1.
@stephentoub stephentoub added this to the 9.0.0 milestone Mar 12, 2024
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-linq
See info in area-owners.md if you want to be subscribed.

@stephentoub stephentoub merged commit 084c9db into dotnet:main Mar 15, 2024
@stephentoub stephentoub deleted the orderby1 branch March 15, 2024 16:03
@github-actions github-actions bot locked and limited conversation to collaborators Apr 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants