1
- using System ;
2
- using BenchmarkDotNet . Attributes ;
1
+ using BenchmarkDotNet . Attributes ;
3
2
using BenchmarkDotNet . Running ;
4
3
using BenchmarkDotNet . Configs ;
5
4
using BenchmarkDotNet . Reports ;
6
5
using BenchmarkDotNet . Filters ;
7
6
using BenchmarkDotNet . Jobs ;
8
7
using System . Text ;
9
- using System . Runtime ;
10
8
using System . Runtime . InteropServices ;
11
- using System . Buffers ;
12
- using System . IO ;
13
- using System . Collections . Generic ;
14
- using System . Linq ;
15
9
using BenchmarkDotNet . Columns ;
16
10
using System . Runtime . Intrinsics ;
17
11
using System . Runtime . Intrinsics . X86 ;
18
- using System . Runtime . Intrinsics . Arm ;
19
- using System . Runtime . CompilerServices ;
20
- using gfoidl . Base64 ;
21
- using System . Buffers . Text ;
22
12
23
13
namespace SimdUnicodeBenchmarks
24
14
{
25
15
26
-
16
+ #pragma warning disable CA1515
27
17
public class Speed : IColumn
28
18
{
29
19
static long GetDirectorySize ( string folderPath )
@@ -76,9 +66,9 @@ public string GetValue(Summary summary, BenchmarkCase benchmarkCase)
76
66
public string Legend { get ; } = "The speed in gigabytes per second" ;
77
67
}
78
68
79
-
80
69
[ SimpleJob ( launchCount : 1 , warmupCount : 5 , iterationCount : 5 ) ]
81
70
[ Config ( typeof ( Config ) ) ]
71
+ #pragma warning disable CA1515
82
72
public class RealDataBenchmark
83
73
{
84
74
#pragma warning disable CA1812
@@ -164,7 +154,8 @@ public Config()
164
154
// Parameters and variables for real data
165
155
[ Params (
166
156
@"data/email/" ,
167
- @"data/dns/swedenzonebase.txt" ) ]
157
+ @"data/dns/swedenzonebase.txt"
158
+ ) ]
168
159
#pragma warning disable CA1051
169
160
public string ? FileName ;
170
161
#pragma warning disable CS8618
@@ -247,7 +238,7 @@ public unsafe void RunScalarDecodingBenchmarkUTF8(string[] data, int[] lengths)
247
238
byte [ ] dataoutput = output [ i ] ;
248
239
int bytesConsumed = 0 ;
249
240
int bytesWritten = 0 ;
250
- SimdBase64 . Base64 . Base64WithWhiteSpaceToBinaryScalar ( base64 . AsSpan ( ) , dataoutput , out bytesConsumed , out bytesWritten , false ) ;
241
+ SimdBase64 . Scalar . Base64 . Base64WithWhiteSpaceToBinaryScalar ( base64 . AsSpan ( ) , dataoutput , out bytesConsumed , out bytesWritten , false ) ;
251
242
if ( bytesWritten != lengths [ i ] )
252
243
{
253
244
Console . WriteLine ( $ "Error: { bytesWritten } != { lengths [ i ] } ") ;
@@ -266,7 +257,7 @@ public unsafe void RunScalarDecodingBenchmarkUTF16(string[] data, int[] lengths)
266
257
byte [ ] dataoutput = output [ i ] ;
267
258
int bytesConsumed = 0 ;
268
259
int bytesWritten = 0 ;
269
- SimdBase64 . Base64 . Base64WithWhiteSpaceToBinaryScalar ( base64 . AsSpan ( ) , dataoutput , out bytesConsumed , out bytesWritten , false ) ;
260
+ SimdBase64 . Scalar . Base64 . Base64WithWhiteSpaceToBinaryScalar ( base64 . AsSpan ( ) , dataoutput , out bytesConsumed , out bytesWritten , false ) ;
270
261
if ( bytesWritten != lengths [ i ] )
271
262
{
272
263
Console . WriteLine ( $ "Error: { bytesWritten } != { lengths [ i ] } ") ;
@@ -285,7 +276,7 @@ public unsafe void RunSSEDecodingBenchmarkUTF8(string[] data, int[] lengths)
285
276
byte [ ] dataoutput = output [ i ] ;
286
277
int bytesConsumed = 0 ;
287
278
int bytesWritten = 0 ;
288
- SimdBase64 . Base64 . DecodeFromBase64SSE ( base64 . AsSpan ( ) , dataoutput , out bytesConsumed , out bytesWritten , false ) ;
279
+ SimdBase64 . SSE . Base64 . DecodeFromBase64SSE ( base64 . AsSpan ( ) , dataoutput , out bytesConsumed , out bytesWritten , false ) ;
289
280
if ( bytesWritten != lengths [ i ] )
290
281
{
291
282
Console . WriteLine ( $ "Error: { bytesWritten } != { lengths [ i ] } ") ;
@@ -304,27 +295,27 @@ public unsafe void RunSSEDecodingBenchmarkUTF16(string[] data, int[] lengths)
304
295
byte [ ] dataoutput = output [ i ] ;
305
296
int bytesConsumed = 0 ;
306
297
int bytesWritten = 0 ;
307
- SimdBase64 . Base64 . DecodeFromBase64SSE ( base64 , dataoutput , out bytesConsumed , out bytesWritten , false ) ;
298
+ SimdBase64 . SSE . Base64 . DecodeFromBase64SSE ( base64 , dataoutput , out bytesConsumed , out bytesWritten , false ) ;
308
299
if ( bytesWritten != lengths [ i ] )
309
300
{
310
301
Console . WriteLine ( $ "Error: { bytesWritten } != { lengths [ i ] } ") ;
311
302
#pragma warning disable CA2201
312
303
throw new Exception ( "Error" ) ;
313
304
}
314
305
}
315
- }
316
-
317
-
318
-
306
+ }
307
+
308
+
309
+
319
310
public unsafe void RunSSEDecodingBenchmarkWithAllocUTF8 ( string [ ] data , int [ ] lengths )
320
311
{
321
312
for ( int i = 0 ; i < FileContent . Length ; i ++ )
322
313
{
323
314
byte [ ] base64 = input [ i ] ;
324
- byte [ ] dataoutput = new byte [ SimdBase64 . Base64 . MaximalBinaryLengthFromBase64Scalar < byte > ( base64 . AsSpan ( ) ) ] ;
315
+ byte [ ] dataoutput = new byte [ SimdBase64 . Scalar . Base64 . MaximalBinaryLengthFromBase64Scalar < byte > ( base64 . AsSpan ( ) ) ] ;
325
316
int bytesConsumed = 0 ;
326
317
int bytesWritten = 0 ;
327
- SimdBase64 . Base64 . DecodeFromBase64SSE ( base64 . AsSpan ( ) , dataoutput , out bytesConsumed , out bytesWritten , false ) ;
318
+ SimdBase64 . SSE . Base64 . DecodeFromBase64SSE ( base64 . AsSpan ( ) , dataoutput , out bytesConsumed , out bytesWritten , false ) ;
328
319
if ( bytesWritten != lengths [ i ] )
329
320
{
330
321
Console . WriteLine ( $ "Error: { bytesWritten } != { lengths [ i ] } ") ;
@@ -340,10 +331,88 @@ public unsafe void RunSSEDecodingBenchmarkWithAllocUTF16(string[] data, int[] le
340
331
{
341
332
string s = FileContent [ i ] ;
342
333
char [ ] base64 = input16 [ i ] ;
343
- byte [ ] dataoutput = new byte [ SimdBase64 . Base64 . MaximalBinaryLengthFromBase64Scalar < char > ( base64 . AsSpan ( ) ) ] ;
334
+ byte [ ] dataoutput = new byte [ SimdBase64 . Scalar . Base64 . MaximalBinaryLengthFromBase64Scalar < char > ( base64 . AsSpan ( ) ) ] ;
335
+ int bytesConsumed = 0 ;
336
+ int bytesWritten = 0 ;
337
+ SimdBase64 . SSE . Base64 . DecodeFromBase64SSE ( base64 . AsSpan ( ) , dataoutput , out bytesConsumed , out bytesWritten , false ) ;
338
+ if ( bytesWritten != lengths [ i ] )
339
+ {
340
+ Console . WriteLine ( $ "Error: { bytesWritten } != { lengths [ i ] } ") ;
341
+ #pragma warning disable CA2201
342
+ throw new Exception ( "Error" ) ;
343
+ }
344
+ }
345
+ }
346
+
347
+
348
+ public unsafe void RunARMDecodingBenchmarkUTF8 ( string [ ] data , int [ ] lengths )
349
+ {
350
+ for ( int i = 0 ; i < FileContent . Length ; i ++ )
351
+ {
352
+ //string s = FileContent[i];
353
+ byte [ ] base64 = input [ i ] ;
354
+ byte [ ] dataoutput = output [ i ] ;
355
+ int bytesConsumed = 0 ;
356
+ int bytesWritten = 0 ;
357
+ SimdBase64 . Arm . Base64 . DecodeFromBase64ARM ( base64 . AsSpan ( ) , dataoutput , out bytesConsumed , out bytesWritten , false ) ;
358
+ if ( bytesWritten != lengths [ i ] )
359
+ {
360
+ Console . WriteLine ( $ "Error: { bytesWritten } != { lengths [ i ] } ") ;
361
+ #pragma warning disable CA2201
362
+ throw new Exception ( "Error" ) ;
363
+ }
364
+ }
365
+ }
366
+
367
+ public unsafe void RunARMDecodingBenchmarkUTF16 ( string [ ] data , int [ ] lengths )
368
+ {
369
+ for ( int i = 0 ; i < FileContent . Length ; i ++ )
370
+ {
371
+ string s = FileContent [ i ] ;
372
+ ReadOnlySpan < char > base64 = s . AsSpan ( ) ;
373
+ byte [ ] dataoutput = output [ i ] ;
374
+ int bytesConsumed = 0 ;
375
+ int bytesWritten = 0 ;
376
+ SimdBase64 . Arm . Base64 . DecodeFromBase64ARM ( base64 , dataoutput , out bytesConsumed , out bytesWritten , false ) ;
377
+ if ( bytesWritten != lengths [ i ] )
378
+ {
379
+ Console . WriteLine ( $ "Error: { bytesWritten } != { lengths [ i ] } ") ;
380
+ #pragma warning disable CA2201
381
+ throw new Exception ( "Error" ) ;
382
+ }
383
+ }
384
+ }
385
+
386
+
387
+
388
+ public unsafe void RunARMDecodingBenchmarkWithAllocUTF8 ( string [ ] data , int [ ] lengths )
389
+ {
390
+ for ( int i = 0 ; i < FileContent . Length ; i ++ )
391
+ {
392
+ byte [ ] base64 = input [ i ] ;
393
+ byte [ ] dataoutput = new byte [ SimdBase64 . Scalar . Base64 . MaximalBinaryLengthFromBase64Scalar < byte > ( base64 . AsSpan ( ) ) ] ;
394
+ int bytesConsumed = 0 ;
395
+ int bytesWritten = 0 ;
396
+ SimdBase64 . Arm . Base64 . DecodeFromBase64ARM ( base64 . AsSpan ( ) , dataoutput , out bytesConsumed , out bytesWritten , false ) ;
397
+ if ( bytesWritten != lengths [ i ] )
398
+ {
399
+ Console . WriteLine ( $ "Error: { bytesWritten } != { lengths [ i ] } ") ;
400
+ #pragma warning disable CA2201
401
+ throw new Exception ( "Error" ) ;
402
+ }
403
+ }
404
+ }
405
+
406
+ public unsafe void RunARMDecodingBenchmarkWithAllocUTF16 ( string [ ] data , int [ ] lengths )
407
+ {
408
+ for ( int i = 0 ; i < FileContent . Length ; i ++ )
409
+ {
410
+ string s = FileContent [ i ] ;
411
+ char [ ] base64 = input16 [ i ] ;
412
+ byte [ ] dataoutput = new byte [ SimdBase64 . Scalar . Base64 . MaximalBinaryLengthFromBase64Scalar < char > ( base64 . AsSpan ( ) ) ] ;
344
413
int bytesConsumed = 0 ;
345
414
int bytesWritten = 0 ;
346
- SimdBase64 . Base64 . DecodeFromBase64SSE ( base64 . AsSpan ( ) , dataoutput , out bytesConsumed , out bytesWritten , false ) ;
415
+ SimdBase64 . Arm . Base64 . DecodeFromBase64ARM ( base64 . AsSpan ( ) , dataoutput , out bytesConsumed , out bytesWritten , false ) ;
347
416
if ( bytesWritten != lengths [ i ] )
348
417
{
349
418
Console . WriteLine ( $ "Error: { bytesWritten } != { lengths [ i ] } ") ;
@@ -419,23 +488,6 @@ public unsafe void DotnetRuntimeBase64RealDataUTF16()
419
488
RunRuntimeDecodingBenchmarkUTF16 ( FileContent , DecodedLengths ) ;
420
489
}
421
490
422
- // Gfoidl does not work correctly with spaces.
423
- /*[Benchmark]
424
- [BenchmarkCategory("default", "gfoidl")]
425
- public unsafe void DotnetGfoildBase64RealDataUTF16()
426
- {
427
- RunGfoidlDecodingBenchmarkUTF16(FileContent, DecodedLengths);
428
- }*/
429
-
430
- // We almost never want to benchmark scalar decoding.
431
- /*[Benchmark]
432
- [BenchmarkCategory("scalar")]
433
- public unsafe void ScalarDecodingRealDataUTF8()
434
- {
435
- RunScalarDecodingBenchmarkUTF8(FileContent, DecodedLengths);
436
- }*/
437
-
438
-
439
491
[ Benchmark ]
440
492
[ BenchmarkCategory ( "SSE" ) ]
441
493
public unsafe void SSEDecodingRealDataUTF8 ( )
@@ -450,6 +502,27 @@ public unsafe void SSEDecodingRealDataWithAllocUTF8()
450
502
RunSSEDecodingBenchmarkWithAllocUTF8 ( FileContent , DecodedLengths ) ;
451
503
}
452
504
505
+ [ Benchmark ]
506
+ [ BenchmarkCategory ( "arm64" ) ]
507
+ public unsafe void ARMDecodingRealDataUTF8 ( )
508
+ {
509
+ RunARMDecodingBenchmarkUTF8 ( FileContent , DecodedLengths ) ;
510
+ }
511
+
512
+ [ Benchmark ]
513
+ [ BenchmarkCategory ( "arm64" ) ]
514
+ public unsafe void ARMDecodingRealDataWithAllocUTF8 ( )
515
+ {
516
+ RunARMDecodingBenchmarkWithAllocUTF8 ( FileContent , DecodedLengths ) ;
517
+ }
518
+
519
+ [ Benchmark ]
520
+ [ BenchmarkCategory ( "arm64" ) ]
521
+ public unsafe void ARMDecodingRealDataUTF16 ( )
522
+ {
523
+ RunARMDecodingBenchmarkUTF16 ( FileContent , DecodedLengths ) ;
524
+ }
525
+
453
526
[ Benchmark ]
454
527
[ BenchmarkCategory ( "SSE" ) ]
455
528
public unsafe void SSEDecodingRealDataUTF16 ( )
@@ -463,8 +536,8 @@ public unsafe void SSEDecodingRealDataWithAllocUTF16()
463
536
{
464
537
RunSSEDecodingBenchmarkWithAllocUTF16 ( FileContent , DecodedLengths ) ;
465
538
}
466
-
467
539
}
540
+ #pragma warning disable CA1515
468
541
public class Program
469
542
{
470
543
static void Main ( string [ ] args )
0 commit comments