13
13
public class Benchmarks
14
14
{
15
15
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?" ;
18
19
19
20
[ Benchmark ]
20
- public string ReplaceStringBuilder ( ) => new StringBuilder ( _text1 ) . Replace ( "Hello" , "Goodbye" ) . ToString ( ) ;
21
+ public string ReplaceStringBuilder ( ) => new StringBuilder ( Text1 ) . Replace ( "Hello" , "Goodbye" ) . ToString ( ) ;
21
22
22
23
[ Benchmark ]
23
- public bool EqualsOrdinalIgnoreCase ( ) => _text1 . Equals ( _text2 , StringComparison . OrdinalIgnoreCase ) ;
24
+ public bool EqualsOrdinalIgnoreCase ( ) => Text1 . Equals ( Text2 , StringComparison . OrdinalIgnoreCase ) ;
24
25
25
26
[ Benchmark ]
26
- public bool EqualsOrdinal ( ) => _text1 . Equals ( _text2 , StringComparison . Ordinal ) ;
27
+ public bool EqualsOrdinal ( ) => Text1 . Equals ( Text2 , StringComparison . Ordinal ) ;
27
28
28
29
[ Benchmark ]
29
- public bool ContainsOrdinalIgnoreCase ( ) => _text1 . Contains ( "Or is it?" , StringComparison . OrdinalIgnoreCase ) ;
30
+ public bool ContainsOrdinalIgnoreCase ( ) => Text1 . Contains ( "Or is it?" , StringComparison . OrdinalIgnoreCase ) ;
30
31
31
32
[ Benchmark ]
32
- public bool ContainsOrdinal ( ) => _text1 . Contains ( "Or is it?" , StringComparison . Ordinal ) ;
33
+ public bool ContainsOrdinal ( ) => Text1 . Contains ( "Or is it?" , StringComparison . Ordinal ) ;
33
34
34
35
[ Benchmark ]
35
- public bool StartsWithOrdinalIgnoreCase ( ) => _text1 . StartsWith ( "Hello World" , StringComparison . OrdinalIgnoreCase ) ;
36
+ public bool StartsWithOrdinalIgnoreCase ( ) => Text1 . StartsWith ( "Hello World" , StringComparison . OrdinalIgnoreCase ) ;
36
37
37
38
[ Benchmark ]
38
- public bool StartsWithOrdinal ( ) => _text1 . StartsWith ( "Hello World" , StringComparison . Ordinal ) ;
39
+ public bool StartsWithOrdinal ( ) => Text1 . StartsWith ( "Hello World" , StringComparison . Ordinal ) ;
39
40
40
41
[ Benchmark ]
41
42
public int LinqMin ( ) => _numbers . Min ( ) ;
@@ -50,7 +51,7 @@ public class Benchmarks
50
51
public string InvokeMethodViaReflection ( )
51
52
{
52
53
var method = typeof ( string ) . GetMethod ( "ToLowerInvariant" , BindingFlags . Public | BindingFlags . Instance ) ;
53
- return ( string ) method . Invoke ( _text1 , null ) ;
54
+ return ( string ) method . Invoke ( Text1 , null ) ;
54
55
}
55
56
56
57
[ Benchmark ]
0 commit comments