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

Improve IndexOf(char, OrdinalIgnoreCase) #73533

Merged
merged 2 commits into from
Aug 8, 2022

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented Aug 7, 2022

A similar trick is used for IndexOf(string, OrdinalIgnoreCase) see here.

Benchmark:

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

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

public class Benchmarks
{
    const string TestStr =
        ".NET Runtime uses third-party libraries or other resources that may be" +
        " distributed under licenses different than the.NET Runtime software.";

    [Benchmark]
    public int IndexOfDash() => TestStr.IndexOf('-', StringComparison.OrdinalIgnoreCase);

    [Benchmark]
    public int IndexOfL() => TestStr.IndexOf('L', StringComparison.OrdinalIgnoreCase);

    [Benchmark]
    public int IndexOfZ() => TestStr.IndexOf('z', StringComparison.OrdinalIgnoreCase);
}
Method Job Toolchain Mean Ratio
IndexOfDash Job-GBURIF \Core_Root_base\corerun.exe 16.125 ns 1.00
IndexOfDash Job-DLWGWE \Core_Root\corerun.exe 7.084 ns 0.44
IndexOfL Job-GBURIF \Core_Root_base\corerun.exe 14.907 ns 1.00
IndexOfL Job-DLWGWE \Core_Root\corerun.exe 5.630 ns 0.38
IndexOfZ Job-GBURIF \Core_Root_base\corerun.exe 16.809 ns 1.00
IndexOfZ Job-DLWGWE \Core_Root\corerun.exe 8.337 ns 0.50

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost assigned EgorBo Aug 7, 2022
@EgorBo EgorBo requested a review from stephentoub August 7, 2022 17:40
Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@ghost
Copy link

ghost commented Aug 7, 2022

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

Issue Details

A similar trick is used for IndexOf(string, OrdinalIgnoreCase) see here.

Benchmark:

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

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

public class Benchmarks
{
    const string TestStr =
        ".NET Runtime uses third-party libraries or other resources that may be" +
        " distributed under licenses different than the.NET Runtime software.";

    [Benchmark]
    public int IndexOfDash() => TestStr.IndexOf('-', StringComparison.OrdinalIgnoreCase);

    [Benchmark]
    public int IndexOfL() => TestStr.IndexOf('L', StringComparison.OrdinalIgnoreCase);

    [Benchmark]
    public int IndexOfZ() => TestStr.IndexOf('z', StringComparison.OrdinalIgnoreCase);
}
Method Job Toolchain Mean Ratio
IndexOfDash Job-GBURIF \Core_Root_base\corerun.exe 16.125 ns 1.00
IndexOfDash Job-DLWGWE \Core_Root\corerun.exe 7.084 ns 0.44
IndexOfL Job-GBURIF \Core_Root_base\corerun.exe 14.907 ns 1.00
IndexOfL Job-DLWGWE \Core_Root\corerun.exe 5.630 ns 0.38
IndexOfZ Job-GBURIF \Core_Root_base\corerun.exe 16.809 ns 1.00
IndexOfZ Job-DLWGWE \Core_Root\corerun.exe 8.337 ns 0.50
Author: EgorBo
Assignees: EgorBo
Labels:

area-System.Runtime

Milestone: -

@EgorBo
Copy link
Member Author

EgorBo commented Aug 8, 2022

Failure is #73247

@EgorBo EgorBo merged commit bee3953 into dotnet:main Aug 8, 2022
@adamsitnik adamsitnik added the tenet-performance Performance related issue label Aug 8, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Sep 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants