runtime
runtime copied to clipboard
Improve IndexOf(char, OrdinalIgnoreCase)
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 |
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: |
|
| Milestone: | - |
Failure is https://github.com/dotnet/runtime/issues/73247