diff --git a/src/benchmarks/micro/libraries/System.Buffers/Base64Tests.cs b/src/benchmarks/micro/libraries/System.Buffers/Base64Tests.cs index 1b4fdb89b5e..d409b04c8f4 100644 --- a/src/benchmarks/micro/libraries/System.Buffers/Base64Tests.cs +++ b/src/benchmarks/micro/libraries/System.Buffers/Base64Tests.cs @@ -52,22 +52,22 @@ public void SetupConvertToBase64CharArray() [GlobalSetup(Target = nameof(Base64Decode))] public void SetupBase64Decode() { - _encodedBytes = ValuesGenerator.Array(NumberOfBytes); + _encodedBytes = ValuesGenerator.ArrayBase64EncodingBytes(NumberOfBytes); _decodedBytes = new byte[Base64.GetMaxEncodedToUtf8Length(NumberOfBytes)]; } [Benchmark] public OperationStatus Base64Decode() => Base64.DecodeFromUtf8(_encodedBytes, _decodedBytes, out _, out _); - [GlobalSetup(Target = nameof(Base64DecodeDetinationTooSmall))] - public void SetupBase64DecodeDetinationTooSmall() + [GlobalSetup(Target = nameof(Base64DecodeDestinationTooSmall))] + public void SetupBase64DecodeDestinationTooSmall() { - _encodedBytes = ValuesGenerator.Array(NumberOfBytes); + _encodedBytes = ValuesGenerator.ArrayBase64EncodingBytes(NumberOfBytes); _decodedBytes = new byte[Base64.GetMaxEncodedToUtf8Length(NumberOfBytes) - 1]; } [Benchmark] - public OperationStatus Base64DecodeDetinationTooSmall() => Base64.DecodeFromUtf8(_encodedBytes, _decodedBytes, out _, out _); + public OperationStatus Base64DecodeDestinationTooSmall() => Base64.DecodeFromUtf8(_encodedBytes, _decodedBytes, out _, out _); #if !NETFRAMEWORK // API added in .NET Core 2.1 [GlobalSetup(Target = nameof(ConvertTryFromBase64Chars))] diff --git a/src/harness/BenchmarkDotNet.Extensions/ValuesGenerator.cs b/src/harness/BenchmarkDotNet.Extensions/ValuesGenerator.cs index f7f988adba3..a99a7c66cc1 100644 --- a/src/harness/BenchmarkDotNet.Extensions/ValuesGenerator.cs +++ b/src/harness/BenchmarkDotNet.Extensions/ValuesGenerator.cs @@ -71,6 +71,32 @@ public static T[] Array(int count) return result; } + public static readonly byte[] s_encodingMap = { + 65, 66, 67, 68, 69, 70, 71, 72, //A..H + 73, 74, 75, 76, 77, 78, 79, 80, //I..P + 81, 82, 83, 84, 85, 86, 87, 88, //Q..X + 89, 90, 97, 98, 99, 100, 101, 102, //Y..Z, a..f + 103, 104, 105, 106, 107, 108, 109, 110, //g..n + 111, 112, 113, 114, 115, 116, 117, 118, //o..v + 119, 120, 121, 122, 48, 49, 50, 51, //w..z, 0..3 + 52, 53, 54, 55, 56, 57, 43, 47 //4..9, +, / + }; + + public static byte[] ArrayBase64EncodingBytes(int count) + { + var result = new byte[count]; + + var random = new Random(Seed); + + for (int i = 0; i < result.Length; i++) + { + int index = random.Next(0, s_encodingMap.Length); + result[i] = s_encodingMap[index]; + } + + return result; + } + public static Dictionary Dictionary(int count) { var dictionary = new Dictionary();