Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slightly better benchmarking code #28

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions benchmark/Benchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public string GetValue(Summary summary, BenchmarkCase benchmarkCase)
}


[SimpleJob(launchCount: 1, warmupCount: 3, iterationCount: 3)]
[SimpleJob(launchCount: 1, warmupCount: 5, iterationCount: 5)]
[Config(typeof(Config))]
public class RealDataBenchmark
{
Expand Down Expand Up @@ -172,6 +172,7 @@ public Config()
public int[] DecodedLengths;
public byte[][] output; // precomputed byte outputs (with correct size)
public byte[][] input; // precomputed byte inputs
public char[][] input16; // precomputed char inputs


public void RunRuntimeDecodingBenchmarkUTF16(string[] data, int[] lengths)
Expand Down Expand Up @@ -261,7 +262,7 @@ public unsafe void RunScalarDecodingBenchmarkUTF16(string[] data, int[] lengths)
for (int i = 0; i < FileContent.Length; i++)
{
string s = FileContent[i];
char[] base64 = s.ToCharArray();
char[] base64 = input16[i];
byte[] dataoutput = output[i];
int bytesConsumed = 0;
int bytesWritten = 0;
Expand Down Expand Up @@ -311,18 +312,16 @@ public unsafe void RunSSEDecodingBenchmarkUTF16(string[] data, int[] lengths)
throw new Exception("Error");
}
}
}
}



public unsafe void RunSSEDecodingBenchmarkWithAllocUTF8(string[] data, int[] lengths)
{
for (int i = 0; i < FileContent.Length; i++)
{
//string s = FileContent[i];
byte[] base64 = input[i];
byte[] dataoutput = new byte[SimdBase64.Base64.MaximalBinaryLengthFromBase64Scalar<byte>(base64.AsSpan())];
//byte[] dataoutput = output[i];
int bytesConsumed = 0;
int bytesWritten = 0;
SimdBase64.Base64.DecodeFromBase64SSE(base64.AsSpan(), dataoutput, out bytesConsumed, out bytesWritten, false);
Expand All @@ -340,7 +339,7 @@ public unsafe void RunSSEDecodingBenchmarkWithAllocUTF16(string[] data, int[] le
for (int i = 0; i < FileContent.Length; i++)
{
string s = FileContent[i];
char[] base64 = s.ToCharArray();
char[] base64 = input16[i];
byte[] dataoutput = new byte[SimdBase64.Base64.MaximalBinaryLengthFromBase64Scalar<char>(base64.AsSpan())];
int bytesConsumed = 0;
int bytesWritten = 0;
Expand All @@ -364,11 +363,13 @@ public void Setup()
DecodedLengths = new int[FileContent.Length];
output = new byte[FileContent.Length][];
input = new byte[FileContent.Length][];
input16 = new char[FileContent.Length][];
for (int i = 0; i < FileContent.Length; i++)
{
DecodedLengths[i] = Convert.FromBase64String(FileContent[i]).Length;
output[i] = new byte[DecodedLengths[i]];
input[i] = Encoding.UTF8.GetBytes(FileContent[i]);
input16[i] = FileContent[i].ToCharArray();
}
}
else if (FileName == "data/email/")
Expand All @@ -378,13 +379,15 @@ public void Setup()
DecodedLengths = new int[fileNames.Length];
output = new byte[FileContent.Length][];
input = new byte[FileContent.Length][];
input16 = new char[FileContent.Length][];

for (int i = 0; i < fileNames.Length; i++)
{
FileContent[i] = File.ReadAllText(fileNames[i]);
DecodedLengths[i] = Convert.FromBase64String(FileContent[i]).Length;
output[i] = new byte[DecodedLengths[i]];
input[i] = Encoding.UTF8.GetBytes(FileContent[i]);
input16[i] = FileContent[i].ToCharArray();
}

}
Expand Down