Skip to content

Commit 33020a6

Browse files
committed
Update CrossChunkMatcherBenchmarks.cs
1 parent e8e1263 commit 33020a6

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/Benchmarks/CrossChunkMatcherBenchmarks.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public class CrossChunkMatcherBenchmarks
66
StringBuilder mediumBuilder = null!;
77
StringBuilder largeBuilder = null!;
88
StringBuilder manyMatchesBuilder = null!;
9+
StringBuilder crossChunkBuilder = null!;
910

1011
[GlobalSetup]
1112
public void Setup()
@@ -40,6 +41,17 @@ public void Setup()
4041
{
4142
manyMatchesBuilder.Append("<TAG>");
4243
}
44+
45+
// Force cross-chunk pattern matching by creating multiple chunks
46+
// Pattern spans across chunk boundaries
47+
crossChunkBuilder = new StringBuilder();
48+
for (var i = 0; i < 100; i++)
49+
{
50+
// Create chunks where <TAG> might span boundaries
51+
crossChunkBuilder.Append("Hello <T");
52+
crossChunkBuilder.Append("AG>world</T");
53+
crossChunkBuilder.Append("AG> test ");
54+
}
4355
}
4456

4557
[Benchmark]
@@ -181,4 +193,23 @@ public void NoMatches()
181193
return null;
182194
});
183195
}
196+
197+
[Benchmark]
198+
public void CrossChunkPatterns()
199+
{
200+
var builder = new StringBuilder(crossChunkBuilder.ToString());
201+
CrossChunkMatcher.ReplaceAll(
202+
builder,
203+
maxLength: 20,
204+
context: (string?) null,
205+
matcher: static (content, _, _) =>
206+
{
207+
if (content.StartsWith("<TAG>"))
208+
{
209+
return new MatchResult(5, "[REPLACED]");
210+
}
211+
212+
return null;
213+
});
214+
}
184215
}

0 commit comments

Comments
 (0)