This repository was archived by the owner on Feb 23, 2026. It is now read-only.
Description Processing dotnet/runtime#117865 (comment) command:
Command
-amd
using BenchmarkDotNet . Attributes ;
using BenchmarkDotNet . Running ;
using System . Buffers ;
BenchmarkRunner . Run < SingleString > ( args : args ) ;
public class SingleString
{
private static readonly SearchValues < string > s_values = SearchValues . Create ( [ Needle ] , StringComparison . Ordinal ) ;
private static readonly SearchValues < string > s_valuesIC = SearchValues . Create ( [ Needle ] , StringComparison . OrdinalIgnoreCase ) ;
private static readonly string s_text_noMatches = new ( 'a' , Length ) ;
private static readonly string s_text_falsePositives = string . Concat ( Enumerable . Repeat ( "Sherlock Holm_s" , Length / Needle . Length ) ) ;
public const int Length = 100_000 ;
public const string Needle = "Sherlock Holmes" ;
[ Benchmark ] public void Throughput ( ) => s_text_noMatches . AsSpan ( ) . Contains ( Needle , StringComparison . Ordinal ) ;
[ Benchmark ] public void SV_Throughput ( ) => s_text_noMatches . AsSpan ( ) . ContainsAny ( s_values ) ;
[ Benchmark ] public void SV_ThroughputIC ( ) => s_text_noMatches . AsSpan ( ) . ContainsAny ( s_valuesIC ) ;
[ Benchmark ] public void FalsePositives ( ) => s_text_falsePositives . AsSpan ( ) . Contains ( Needle , StringComparison . Ordinal ) ;
[ Benchmark ] public void SV_FalsePositives ( ) => s_text_falsePositives . AsSpan ( ) . ContainsAny ( s_values ) ;
[ Benchmark ] public void SV_FalsePositivesIC ( ) => s_text_falsePositives . AsSpan ( ) . ContainsAny ( s_valuesIC ) ;
}
(EgorBot will reply in this issue )
Reactions are currently unavailable