@@ -15,17 +15,19 @@ namespace SimdUnicodeBenchmarks
1515 public class Checker
1616 {
1717 List < char [ ] > names ;
18- List < char [ ] > nonAsciichars ;
18+ List < char [ ] > nonAsciichars ;
1919 public List < byte [ ] > nonAsciiByteArrays ; // Declare at the class level
2020
2121 List < bool > results ;
2222
2323 public static bool RuntimeIsAsciiApproach ( ReadOnlySpan < char > s )
2424 {
25+
2526 // The runtime as of NET 8.0 has a dedicated method for this, but
2627 // it is not available prior to that, so let us branch.
2728#if NET8_0_OR_GREATER
28- return Ascii . IsValid ( s ) ;
29+ return System . Text . Ascii . IsValid ( s ) ;
30+
2931#else
3032 foreach ( char c in s )
3133 {
@@ -38,6 +40,8 @@ public static bool RuntimeIsAsciiApproach(ReadOnlySpan<char> s)
3840 return true ;
3941#endif
4042 }
43+
44+
4145 public static char [ ] GetRandomASCIIString ( uint n )
4246 {
4347 var allowedChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ01234567é89" ;
@@ -56,8 +60,8 @@ public static char[] GetRandomASCIIString(uint n)
5660 public static char [ ] GetRandomNonASCIIString ( uint n )
5761 {
5862 // Chose a few Latin Extended-A and Latin Extended-B characters alongside ASCII chars
59- var allowedChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ01234567é89šžŸũŭůűųŷŹźŻżŽ" ;
60-
63+ var allowedChars = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ01234567é89šžŸũŭůűųŷŹźŻżŽ" ;
64+
6165 var chars = new char [ n ] ;
6266 var rd = new Random ( 12345 ) ; // fixed seed
6367
@@ -133,14 +137,26 @@ public void TestErrorGetIndexOfFirstNonAsciiByteBenchmark()
133137 {
134138 fixed ( byte * pNonAscii = nonAsciiBytes )
135139 {
136- nuint result = Ascii . GetIndexOfFirstNonAsciiByte ( pNonAscii , ( nuint ) nonAsciiBytes . Length ) ;
140+ nuint result = SimdUnicode . Ascii . GetIndexOfFirstNonAsciiByte ( pNonAscii , ( nuint ) nonAsciiBytes . Length ) ;
137141 }
138142 }
139143 }
140144 }
141145
142-
143-
146+ [ Benchmark ]
147+ public void RuntimeGetIndexOfFirstNonAsciiByteBenchmark ( )
148+ {
149+ foreach ( byte [ ] nonAsciiBytes in nonAsciiByteArrays ) // Use nonAsciiByteArrays directly
150+ {
151+ unsafe
152+ {
153+ fixed ( byte * pNonAscii = nonAsciiBytes )
154+ {
155+ nuint result = Competition . Ascii . GetIndexOfFirstNonAsciiByte ( pNonAscii , ( nuint ) nonAsciiBytes . Length ) ;
156+ }
157+ }
158+ }
159+ }
144160 }
145161
146162 public class Program
0 commit comments