Skip to content

Commit 2c4ca94

Browse files
authored
Merge pull request #25 from simdutf/add_UTF16_support
Add_UTF16_support + fix/test array OutOfIndex error
2 parents 4f5177d + d25489f commit 2c4ca94

File tree

7 files changed

+3089
-565
lines changed

7 files changed

+3089
-565
lines changed

benchmark/Benchmark.cs

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,27 @@ public unsafe void RunScalarDecodingBenchmarkUTF8(string[] data, int[] lengths)
254254
throw new Exception("Error");
255255
}
256256
}
257-
}
258-
257+
}
258+
259+
public unsafe void RunScalarDecodingBenchmarkUTF16(string[] data, int[] lengths)
260+
{
261+
for (int i = 0; i < FileContent.Length; i++)
262+
{
263+
string s = FileContent[i];
264+
char[] base64 = s.ToCharArray();
265+
byte[] dataoutput = output[i];
266+
int bytesConsumed = 0;
267+
int bytesWritten = 0;
268+
SimdBase64.Base64.Base64WithWhiteSpaceToBinaryScalar(base64.AsSpan(), dataoutput, out bytesConsumed, out bytesWritten, false);
269+
if (bytesWritten != lengths[i])
270+
{
271+
Console.WriteLine($"Error: {bytesWritten} != {lengths[i]}");
272+
#pragma warning disable CA2201
273+
throw new Exception("Error");
274+
}
275+
}
276+
}
277+
259278
public unsafe void RunSSEDecodingBenchmarkUTF8(string[] data, int[] lengths)
260279
{
261280
for (int i = 0; i < FileContent.Length; i++)
@@ -275,13 +294,34 @@ public unsafe void RunSSEDecodingBenchmarkUTF8(string[] data, int[] lengths)
275294
}
276295
}
277296

297+
public unsafe void RunSSEDecodingBenchmarkUTF16(string[] data, int[] lengths)
298+
{
299+
for (int i = 0; i < FileContent.Length; i++)
300+
{
301+
string s = FileContent[i];
302+
ReadOnlySpan<char> base64 = s.AsSpan();
303+
byte[] dataoutput = output[i];
304+
int bytesConsumed = 0;
305+
int bytesWritten = 0;
306+
SimdBase64.Base64.DecodeFromBase64SSE(base64, dataoutput, out bytesConsumed, out bytesWritten, false);
307+
if (bytesWritten != lengths[i])
308+
{
309+
Console.WriteLine($"Error: {bytesWritten} != {lengths[i]}");
310+
#pragma warning disable CA2201
311+
throw new Exception("Error");
312+
}
313+
}
314+
}
315+
316+
317+
278318
public unsafe void RunSSEDecodingBenchmarkWithAllocUTF8(string[] data, int[] lengths)
279319
{
280320
for (int i = 0; i < FileContent.Length; i++)
281321
{
282322
//string s = FileContent[i];
283323
byte[] base64 = input[i];
284-
byte[] dataoutput = new byte[SimdBase64.Base64.MaximalBinaryLengthFromBase64Scalar(base64.AsSpan())];
324+
byte[] dataoutput = new byte[SimdBase64.Base64.MaximalBinaryLengthFromBase64Scalar<byte>(base64.AsSpan())];
285325
//byte[] dataoutput = output[i];
286326
int bytesConsumed = 0;
287327
int bytesWritten = 0;
@@ -295,6 +335,25 @@ public unsafe void RunSSEDecodingBenchmarkWithAllocUTF8(string[] data, int[] len
295335
}
296336
}
297337

338+
public unsafe void RunSSEDecodingBenchmarkWithAllocUTF16(string[] data, int[] lengths)
339+
{
340+
for (int i = 0; i < FileContent.Length; i++)
341+
{
342+
string s = FileContent[i];
343+
char[] base64 = s.ToCharArray();
344+
byte[] dataoutput = new byte[SimdBase64.Base64.MaximalBinaryLengthFromBase64Scalar<char>(base64.AsSpan())];
345+
int bytesConsumed = 0;
346+
int bytesWritten = 0;
347+
SimdBase64.Base64.DecodeFromBase64SSE(base64.AsSpan(), dataoutput, out bytesConsumed, out bytesWritten, false);
348+
if (bytesWritten != lengths[i])
349+
{
350+
Console.WriteLine($"Error: {bytesWritten} != {lengths[i]}");
351+
#pragma warning disable CA2201
352+
throw new Exception("Error");
353+
}
354+
}
355+
}
356+
298357
[GlobalSetup]
299358
public void Setup()
300359
{
@@ -388,6 +447,20 @@ public unsafe void SSEDecodingRealDataWithAllocUTF8()
388447
RunSSEDecodingBenchmarkWithAllocUTF8(FileContent, DecodedLengths);
389448
}
390449

450+
[Benchmark]
451+
[BenchmarkCategory("SSE")]
452+
public unsafe void SSEDecodingRealDataUTF16()
453+
{
454+
RunSSEDecodingBenchmarkUTF16(FileContent, DecodedLengths);
455+
}
456+
457+
[Benchmark]
458+
[BenchmarkCategory("SSE")]
459+
public unsafe void SSEDecodingRealDataWithAllocUTF16()
460+
{
461+
RunSSEDecodingBenchmarkWithAllocUTF16(FileContent, DecodedLengths);
462+
}
463+
391464
}
392465
public class Program
393466
{

0 commit comments

Comments
 (0)