[wasm] Add index of string span measurement (#89294)
authorRadek Doulik <radek.doulik@gmail.com>
Fri, 21 Jul 2023 13:26:09 +0000 (15:26 +0200)
committerGitHub <noreply@github.com>
Fri, 21 Jul 2023 13:26:09 +0000 (15:26 +0200)
src/mono/sample/wasm/browser-bench/Span.cs

index 2317820..ecd18ac 100644 (file)
@@ -19,6 +19,7 @@ namespace Sample
                 new ReverseChar(),
                 new IndexOfByte(),
                 new IndexOfChar(),
+                new IndexOfString(),
                 new SequenceEqualByte(),
                 new SequenceEqualChar(),
             };
@@ -83,6 +84,22 @@ namespace Sample
             }
         }
 
+        class IndexOfString : SpanMeasurement
+        {
+            public override string Name => "IndexOf strings";
+
+            string input = "string1";
+            string value = "string2";
+
+            public override void RunStep()
+            {
+                ReadOnlySpan<char> inputSpan = input.AsSpan();
+                ReadOnlySpan<char> valueSpan = value.AsSpan();
+
+                inputSpan.IndexOf(valueSpan, StringComparison.InvariantCulture);
+            }
+        }
+
         abstract class SpanCharMeasurement : SpanMeasurement
         {
             protected char[] data;