Skip to content

Commit b2d72ef

Browse files
committed
.
1 parent 3ef1fab commit b2d72ef

File tree

3 files changed

+6
-94
lines changed

3 files changed

+6
-94
lines changed

src/Benchmarks/FilterLinesBenchmarks.cs

Lines changed: 4 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -10,93 +10,6 @@ public class FilterLinesBenchmarks
1010
public void Setup()
1111
{
1212
// Small: ~1KB, 20 lines
13-
_smallInput = CreateTestData(20, 50);
14-
15-
// Medium: ~50KB, 1000 lines
16-
_mediumInput = CreateTestData(1000, 50);
17-
18-
// Large: ~500KB, 10000 lines
19-
_largeInput = CreateTestData(10000, 50);
20-
}
21-
22-
private static StringBuilder CreateTestData(int lineCount, int charsPerLine)
23-
{
24-
var sb = new StringBuilder();
25-
for (var i = 0; i < lineCount; i++)
26-
{
27-
sb.Append(new string('x', charsPerLine));
28-
sb.Append(i);
29-
sb.AppendLine();
30-
}
31-
return sb;
32-
}
33-
34-
// Remove every other line
35-
private static bool RemoveEvenLines(ReadOnlySpan<char> line) =>
36-
line.Length > 0 && char.IsDigit(line[^1]) && (line[^1] - '0') % 2 == 0;
37-
38-
[Benchmark(Baseline = true)]
39-
public void Original_Small()
40-
{
41-
var sb = new StringBuilder(_smallInput.ToString());
42-
sb.FilterLines_Original(RemoveEvenLines);
43-
}
44-
45-
[Benchmark]
46-
public void SpanBased_Small()
47-
{
48-
var sb = new StringBuilder(_smallInput.ToString());
49-
sb.FilterLines_SpanBased(RemoveEvenLines);
50-
}
51-
52-
[Benchmark]
53-
public void ArrayPool_Small()
54-
{
55-
var sb = new StringBuilder(_smallInput.ToString());
56-
sb.FilterLines_ArrayPool(RemoveEvenLines);
57-
}
58-
59-
[Benchmark]
60-
public void Original_Medium()
61-
{
62-
var sb = new StringBuilder(_mediumInput.ToString());
63-
sb.FilterLines_Original(RemoveEvenLines);
64-
}
65-
66-
[Benchmark]
67-
public void SpanBased_Medium()
68-
{
69-
var sb = new StringBuilder(_mediumInput.ToString());
70-
sb.FilterLines_SpanBased(RemoveEvenLines);
71-
}
72-
73-
[Benchmark]
74-
public void ArrayPool_Medium()
75-
{
76-
var sb = new StringBuilder(_mediumInput.ToString());
77-
sb.FilterLines_ArrayPool(RemoveEvenLines);
78-
}
79-
80-
[Benchmark]
81-
public void Original_Large()
82-
{
83-
var sb = new StringBuilder(_largeInput.ToString());
84-
sb.FilterLines_Original(RemoveEvenLines);
85-
}
86-
87-
[Benchmark]
88-
public void SpanBased_Large()
89-
{
90-
var sb = new StringBuilder(_largeInput.ToString());
91-
sb.FilterLines_SpanBased(RemoveEvenLines);
92-
}
93-
94-
[Benchmark]
95-
public void ArrayPool_Large()
96-
{
97-
var sb = new StringBuilder(_largeInput.ToString());
98-
sb.FilterLines_ArrayPool(RemoveEvenLines);
99-
10013
smallInput = CreateTestData(20, 50);
10114

10215
// Medium: ~50KB, 1000 lines
@@ -106,6 +19,10 @@ public void ArrayPool_Large()
10619
largeInput = CreateTestData(10000, 50);
10720
}
10821

22+
// Remove every other line
23+
static bool RemoveEvenLines(ReadOnlySpan<char> line) =>
24+
line.Length > 0 && char.IsDigit(line[^1]) && (line[^1] - '0') % 2 == 0;
25+
10926
static StringBuilder CreateTestData(int lineCount, int charsPerLine)
11027
{
11128
var builder = new StringBuilder();
@@ -118,10 +35,6 @@ static StringBuilder CreateTestData(int lineCount, int charsPerLine)
11835
return builder;
11936
}
12037

121-
// Remove every other line
122-
static bool RemoveEvenLines(ReadOnlySpan<char> line) =>
123-
line.Length > 0 && char.IsDigit(line[^1]) && (line[^1] - '0') % 2 == 0;
124-
12538
[Benchmark(Baseline = true)]
12639
public void Small()
12740
{

src/Verify.Tests/LinesScrubberTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ public void FilterLines_LargeContent()
278278
var lines = Enumerable.Range(1, 1000).Select(i => $"line{i}");
279279
var builder = new StringBuilder(string.Join('\n', lines));
280280

281-
builder.FilterLines(line => int.Parse(line.Slice(4)) % 2 == 0);
281+
//TODO: remove the ToString when added to polyfill
282+
builder.FilterLines(line => int.Parse(line.Slice(4).ToString()) % 2 == 0);
282283

283284
var remaining = builder.ToString().Split('\n');
284285
Assert.Equal(500, remaining.Length);

src/Verify/Extensions.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// ReSharper disable UnusedVariable
22

3-
public delegate bool RemoveLine(CharSpan line);
4-
53
static class Extensions
64
{
75
static HashSet<Type> numericTypes =

0 commit comments

Comments
 (0)