@@ -26,7 +26,7 @@ public class StringExtensionsPerfTestRunner : PerfTestRunner
26
26
private string _commaDelimitedString ;
27
27
private string _stringToTrim ;
28
28
29
- [ Benchmark ( Description = nameof ( StringExtensions . ComputeSha256Hash ) ) ]
29
+ [ Benchmark ( Description = nameof ( StringExtensions . ComputeSHA256Hash ) ) ]
30
30
public void ComputeMD5Hash ( )
31
31
{
32
32
var result = LongTestString . ComputeSha256Hash ( ) ;
@@ -69,7 +69,7 @@ public void DefaultIfNullOrEmpty()
69
69
[ Benchmark ( Description = nameof ( StringExtensions . DelimitedStringToArray ) ) ]
70
70
public void DelimitedStringToArray ( )
71
71
{
72
- var result = _commaDelimitedString . DelimitedStringToArray ( ) ;
72
+ var result = this . _commaDelimitedString . DelimitedStringToArray ( ) ;
73
73
74
74
base . Consumer . Consume ( result ) ;
75
75
}
@@ -90,6 +90,16 @@ public void EqualsOrBothNullOrEmpty()
90
90
base . Consumer . Consume ( result ) ;
91
91
}
92
92
93
+ [ Benchmark ( Description = nameof ( StringExtensions . FromBase64 ) + ":" + nameof ( StringExtensions . ToBase64 ) ) ]
94
+ public void FromBase64 ( )
95
+ {
96
+ var base64 = RandomData . GenerateWord ( 100 ) . ToBase64 ( ) ;
97
+
98
+ var result = base64 . FromBase64 ( ) ;
99
+
100
+ base . Consumer . Consume ( result ) ;
101
+ }
102
+
93
103
[ Benchmark ( Description = nameof ( StringExtensions . HasValue ) ) ]
94
104
public void HasValue ( )
95
105
{
@@ -133,46 +143,46 @@ public void IsWhitespaceChar()
133
143
[ Benchmark ( Description = nameof ( StringExtensions . IsWhitespace ) + ":String" ) ]
134
144
public void IsWhitespaceString ( )
135
145
{
136
- var result = _stringToTrim . IsWhitespace ( ) ;
146
+ var result = this . _stringToTrim . IsWhitespace ( ) ;
137
147
138
148
base . Consumer . Consume ( result ) ;
139
149
}
140
150
141
151
public override void Setup ( )
142
152
{
143
153
base . Setup ( ) ;
144
- _commaDelimitedString = RandomData . GenerateWords ( 10 , 5 , 10 ) . ToDelimitedString ( ) ;
145
- _stringToTrim = " " + LongTestString + " " ;
154
+ this . _commaDelimitedString = RandomData . GenerateWords ( 10 , 5 , 10 ) . ToDelimitedString ( ) ;
155
+ this . _stringToTrim = " " + LongTestString + " " ;
146
156
}
147
157
148
158
[ Benchmark ( Description = nameof ( StringExtensions . Split ) + ":Char Separator" ) ]
149
159
public void SplitCharSeparator ( )
150
160
{
151
- var result = _commaDelimitedString . Split ( ControlChars . Comma , StringSplitOptions . None ) ;
161
+ var result = this . _commaDelimitedString . Split ( ControlChars . Comma , StringSplitOptions . None ) ;
152
162
153
163
base . Consumer . Consume ( result ) ;
154
164
}
155
165
156
166
[ Benchmark ( Description = nameof ( StringExtensions . Split ) + ":Char Separator-Count" ) ]
157
167
public void SplitCharSeparatorCount ( )
158
168
{
159
- var result = _commaDelimitedString . Split ( ControlChars . Comma , 2 , StringSplitOptions . None ) ;
169
+ var result = this . _commaDelimitedString . Split ( ControlChars . Comma , 2 , StringSplitOptions . None ) ;
160
170
161
171
base . Consumer . Consume ( result ) ;
162
172
}
163
173
164
174
[ Benchmark ( Description = nameof ( StringExtensions . Split ) + ":Char Separator-RemoveEmptyEntries" ) ]
165
175
public void SplitCharSeparatorRemoveEmptyEntries ( )
166
176
{
167
- var result = _commaDelimitedString . Split ( ControlChars . Comma , StringSplitOptions . RemoveEmptyEntries ) ;
177
+ var result = this . _commaDelimitedString . Split ( ControlChars . Comma , StringSplitOptions . RemoveEmptyEntries ) ;
168
178
169
179
base . Consumer . Consume ( result ) ;
170
180
}
171
181
172
182
[ Benchmark ( Description = nameof ( StringExtensions . Split ) + ":Char Separator-Count-RemoveEmptyEntries" ) ]
173
183
public void SplitCharSeparatorRemoveEmptyEntriesCount ( )
174
184
{
175
- var result = _commaDelimitedString . Split ( ControlChars . Comma , 2 , StringSplitOptions . RemoveEmptyEntries ) ;
185
+ var result = this . _commaDelimitedString . Split ( ControlChars . Comma , 2 , StringSplitOptions . RemoveEmptyEntries ) ;
176
186
177
187
base . Consumer . Consume ( result ) ;
178
188
}
@@ -181,31 +191,31 @@ public void SplitCharSeparatorRemoveEmptyEntriesCount()
181
191
[ Benchmark ( Description = nameof ( StringExtensions . Split ) + ":String Separator" ) ]
182
192
public void SplitStringSeparator ( )
183
193
{
184
- var result = _commaDelimitedString . Split ( "," , StringSplitOptions . None ) ;
194
+ var result = this . _commaDelimitedString . Split ( "," , StringSplitOptions . None ) ;
185
195
186
196
base . Consumer . Consume ( result ) ;
187
197
}
188
198
189
199
[ Benchmark ( Description = nameof ( StringExtensions . Split ) + ":String Separator-Count" ) ]
190
200
public void SplitStringSeparatorCount ( )
191
201
{
192
- var result = _commaDelimitedString . Split ( "," , 2 , StringSplitOptions . None ) ;
202
+ var result = this . _commaDelimitedString . Split ( "," , 2 , StringSplitOptions . None ) ;
193
203
194
204
base . Consumer . Consume ( result ) ;
195
205
}
196
206
197
207
[ Benchmark ( Description = nameof ( StringExtensions . Split ) + ":String Separator-RemoveEmptyEntries" ) ]
198
208
public void SplitStringSeparatorRemoveEmptyEntries ( )
199
209
{
200
- var result = _commaDelimitedString . Split ( "," , StringSplitOptions . RemoveEmptyEntries ) ;
210
+ var result = this . _commaDelimitedString . Split ( "," , StringSplitOptions . RemoveEmptyEntries ) ;
201
211
202
212
base . Consumer . Consume ( result ) ;
203
213
}
204
214
205
215
[ Benchmark ( Description = nameof ( StringExtensions . Split ) + ":String Separator-Count-RemoveEmptyEntries" ) ]
206
216
public void SplitStringSeparatorRemoveEmptyEntriesCount ( )
207
217
{
208
- var result = _commaDelimitedString . Split ( "," , 2 , StringSplitOptions . RemoveEmptyEntries ) ;
218
+ var result = this . _commaDelimitedString . Split ( "," , 2 , StringSplitOptions . RemoveEmptyEntries ) ;
209
219
210
220
base . Consumer . Consume ( result ) ;
211
221
}
@@ -234,24 +244,6 @@ public void SubstringTrim()
234
244
base . Consumer . Consume ( result ) ;
235
245
}
236
246
237
- [ Benchmark ( Description = nameof ( StringExtensions . ToTrimmed ) ) ]
238
- public void ToTrimmedString ( )
239
- {
240
- var result = _stringToTrim . ToTrimmed ( ) ;
241
-
242
- base . Consumer . Consume ( result ) ;
243
- }
244
-
245
- [ Benchmark ( Description = nameof ( StringExtensions . FromBase64 ) + ":" + nameof ( StringExtensions . ToBase64 ) ) ]
246
- public void FromBase64 ( )
247
- {
248
- var base64 = RandomData . GenerateWord ( 100 ) . ToBase64 ( ) ;
249
-
250
- var result = base64 . FromBase64 ( ) ;
251
-
252
- base . Consumer . Consume ( result ) ;
253
- }
254
-
255
247
[ Benchmark ( Description = nameof ( StringExtensions . ToTitleCase ) ) ]
256
248
public void ToTitleCase ( )
257
249
{
@@ -261,5 +253,13 @@ public void ToTitleCase()
261
253
base . Consumer . Consume ( words . ToTitleCase ( ) ) ;
262
254
}
263
255
256
+ [ Benchmark ( Description = nameof ( StringExtensions . ToTrimmed ) ) ]
257
+ public void ToTrimmedString ( )
258
+ {
259
+ var result = this . _stringToTrim . ToTrimmed ( ) ;
260
+
261
+ base . Consumer . Consume ( result ) ;
262
+ }
263
+
264
264
}
265
265
}
0 commit comments