Skip to content

25% regression in string search benchmark #106624

Open
@stephentoub

Description

This benchmark regresses by ~25% for me between .NET 8 and .NET 9:

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running; 

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

[HideColumns("Job", "Error", "StdDev", "Median", "RatioSD")]
public class Tests
{
    private static readonly string s_input = new HttpClient().GetStringAsync("https://gutenberg.org/cache/epub/2600/pg2600.txt").Result;
    private static readonly string[] s_daysOfWeek = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];

    [Benchmark]
    public bool Contains_Iterate()
    {
         ReadOnlySpan<char> input = s_input;
         for (int i = 0; i < input.Length; i++)
         {
             foreach (string dow in s_daysOfWeek)
             {
                 if (input.Slice(i).StartsWith(dow, StringComparison.OrdinalIgnoreCase))
                 {
                     return true;
                 }
             }
         }
         return false;
     }
}

This is on a machine without AVX512.

@EgorBo confirmed he also sees the same regression:
"From a quick look at ASM diffs (https://www.diffchecker.com/7Teb6dKS/) it looks like some BB layout reshuffling (Aman/Andy) or strength reduction/IV (Jakob)"

cc: @AndyAyersMS , @amanasifkhalid , @jakobbotsch

Activity

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

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions