runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Improve IndexOf(char, OrdinalIgnoreCase)

Open EgorBo opened this issue 3 years ago • 2 comments
trafficstars

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

EgorBo avatar Aug 07 '22 17:08 EgorBo

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.

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: -

msftbot[bot] avatar Aug 07 '22 19:08 msftbot[bot]

Failure is https://github.com/dotnet/runtime/issues/73247

EgorBo avatar Aug 08 '22 08:08 EgorBo