Skip to content

Commit 25333b4

Browse files
committed
Update SB
1 parent 2c6c552 commit 25333b4

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

BenchmarkDotNet8/Program.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,30 @@
1313
public class Benchmarks
1414
{
1515
private readonly List<int> _numbers = Enumerable.Range(0, 10000).Select(s => Random.Shared.Next()).ToList();
16-
private readonly string _text1 = "Hello woRld! ThIs is a test.It CoUlD be a lot longer, but it'S not. Or is it?";
17-
private readonly string _text2 = "Hello world! This is a test.it could be a lot longer, but it's not. Or is it?";
16+
private const string Text1 = "Hello woRld! ThIs is a test.It CoUlD be a lot longer, but it'S not. Or is it?";
17+
18+
private const string Text2 = "Hello world! This is a test.it could be a lot longer, but it's not. Or is it?";
1819

1920
[Benchmark]
20-
public string ReplaceStringBuilder() => new StringBuilder(_text1).Replace("Hello", "Goodbye").ToString();
21+
public string ReplaceStringBuilder() => new StringBuilder(Text1).Replace("Hello", "Goodbye").ToString();
2122

2223
[Benchmark]
23-
public bool EqualsOrdinalIgnoreCase() => _text1.Equals(_text2, StringComparison.OrdinalIgnoreCase);
24+
public bool EqualsOrdinalIgnoreCase() => Text1.Equals(Text2, StringComparison.OrdinalIgnoreCase);
2425

2526
[Benchmark]
26-
public bool EqualsOrdinal() => _text1.Equals(_text2, StringComparison.Ordinal);
27+
public bool EqualsOrdinal() => Text1.Equals(Text2, StringComparison.Ordinal);
2728

2829
[Benchmark]
29-
public bool ContainsOrdinalIgnoreCase() => _text1.Contains("Or is it?", StringComparison.OrdinalIgnoreCase);
30+
public bool ContainsOrdinalIgnoreCase() => Text1.Contains("Or is it?", StringComparison.OrdinalIgnoreCase);
3031

3132
[Benchmark]
32-
public bool ContainsOrdinal() => _text1.Contains("Or is it?", StringComparison.Ordinal);
33+
public bool ContainsOrdinal() => Text1.Contains("Or is it?", StringComparison.Ordinal);
3334

3435
[Benchmark]
35-
public bool StartsWithOrdinalIgnoreCase() => _text1.StartsWith("Hello World", StringComparison.OrdinalIgnoreCase);
36+
public bool StartsWithOrdinalIgnoreCase() => Text1.StartsWith("Hello World", StringComparison.OrdinalIgnoreCase);
3637

3738
[Benchmark]
38-
public bool StartsWithOrdinal() => _text1.StartsWith("Hello World", StringComparison.Ordinal);
39+
public bool StartsWithOrdinal() => Text1.StartsWith("Hello World", StringComparison.Ordinal);
3940

4041
[Benchmark]
4142
public int LinqMin() => _numbers.Min();
@@ -50,7 +51,7 @@ public class Benchmarks
5051
public string InvokeMethodViaReflection()
5152
{
5253
var method = typeof(string).GetMethod("ToLowerInvariant", BindingFlags.Public | BindingFlags.Instance);
53-
return (string)method.Invoke(_text1, null);
54+
return (string)method.Invoke(Text1, null);
5455
}
5556

5657
[Benchmark]

0 commit comments

Comments
 (0)