Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 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
7 changes: 7 additions & 0 deletions Common.sln
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Internal.AspNetCore.Analyze
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Internal.AspNetCore.Analyzers.Tests", "test\Internal.AspNetCore.Analyzers.Tests\Internal.AspNetCore.Analyzers.Tests.csproj", "{1A579BD1-A4C4-4B1B-B092-D1670DF7F239}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Extensions.Internal.Benchmarks", "benchmarks\Microsoft.Extensions.Internal.Benchmarks\Microsoft.Extensions.Internal.Benchmarks.csproj", "{7EAB9B74-5E5E-4D93-BA1E-865906C50676}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -137,6 +139,10 @@ Global
{1A579BD1-A4C4-4B1B-B092-D1670DF7F239}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1A579BD1-A4C4-4B1B-B092-D1670DF7F239}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1A579BD1-A4C4-4B1B-B092-D1670DF7F239}.Release|Any CPU.Build.0 = Release|Any CPU
{7EAB9B74-5E5E-4D93-BA1E-865906C50676}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7EAB9B74-5E5E-4D93-BA1E-865906C50676}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7EAB9B74-5E5E-4D93-BA1E-865906C50676}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7EAB9B74-5E5E-4D93-BA1E-865906C50676}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -157,6 +163,7 @@ Global
{B439E0C8-F892-4AC5-BBF7-63BCDAACA7A9} = {6878D8F1-6DCE-4677-AA1A-4D14BA6D2D60}
{FACBCBCB-D043-4AE8-A22D-A683040999DD} = {FEAA3936-5906-4383-B750-F07FE1B156C5}
{1A579BD1-A4C4-4B1B-B092-D1670DF7F239} = {6878D8F1-6DCE-4677-AA1A-4D14BA6D2D60}
{7EAB9B74-5E5E-4D93-BA1E-865906C50676} = {A9A93AF9-2113-4321-AD20-51F60FF8B2BD}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {371030CF-B541-4BA9-9F54-3C7563415CF1}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<OutputType>Exe</OutputType>
<ServerGarbageCollection>true</ServerGarbageCollection>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IsPackable>false</IsPackable>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\..\shared\Microsoft.AspNetCore.BenchmarkRunner.Sources\**\*.cs">
<Link>Shared\%(FileName)%(Extension)</Link>
</Compile>
</ItemGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="$(BenchmarkDotNetPackageVersion)" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="$(SystemRuntimeCompilerServicesUnsafePackageVersion)" />
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\..\shared\Microsoft.Extensions.WebEncoders.Sources\**\*.cs" />
<EmbeddedResource Include="..\..\shared\*.Sources\**\*.resx" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

[assembly: BenchmarkDotNet.Attributes.AspNetCoreBenchmark]
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System;
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;

namespace Microsoft.Extensions.Internal.Benchmarks
{
public class WebEncodersBenchmarks
{
private const int ByteArraySize = 500;
private readonly byte[] _data;
private readonly string _dataEncoded;
private readonly byte[] _dataWithOffset;
private readonly string _dataWithOffsetEncoded;
private readonly byte[] _guid;
private readonly string _guidEncoded;

public WebEncodersBenchmarks()
{
var random = new Random();
_data = new byte[ByteArraySize];
random.NextBytes(_data);
_dataEncoded = WebEncoders.Base64UrlEncode(_data);

_dataWithOffset = new byte[3].Concat(_data).Concat(new byte[2]).ToArray();
_dataWithOffsetEncoded = "xx" + _dataEncoded + "yyy";

_guid = Guid.NewGuid().ToByteArray();
_guidEncoded = WebEncoders.Base64UrlEncode(_guid);
}

[Benchmark]
public byte[] Base64UrlDecode_Data()
{
return WebEncoders.Base64UrlDecode(_dataEncoded);
}

[Benchmark]
public byte[] Base64UrlDecode_DataWithOffset()
{
return WebEncoders.Base64UrlDecode(_dataWithOffsetEncoded, 2, _dataEncoded.Length);
}

[Benchmark]
public byte[] Base64UrlDecode_Guid()
{
return WebEncoders.Base64UrlDecode(_guidEncoded);
}

[Benchmark]
public string Base64UrlEncode_Data()
{
return WebEncoders.Base64UrlEncode(_data);
}

[Benchmark]
public string Base64UrlEncode_DataWithOffset()
{
return WebEncoders.Base64UrlEncode(_dataWithOffset, 3, _data.Length);
}

[Benchmark]
public string Base64UrlEncode_Guid()
{
return WebEncoders.Base64UrlEncode(_guid);
}

[Benchmark]
public int GetArraySizeRequiredToDecode()
{
return WebEncoders.GetArraySizeRequiredToDecode(ByteArraySize);
}

[Benchmark]
public int GetArraySizeRequiredToEncode()
{
return WebEncoders.GetArraySizeRequiredToEncode(ByteArraySize);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ internal static class EncoderResources
/// </summary>
internal static readonly string WebEncoders_MalformedInput = "Malformed input: {0} is an invalid input length.";

/// <summary>
/// Invalid input, that doesn't conform a base64 string.
/// </summary>
internal static readonly string WebEncoders_InvalidInput = "The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.";

/// <summary>
/// Destination buffer is too small.
/// </summary>
internal static readonly string WebEncoders_DestinationTooSmall = "The destination buffer is too small.";

/// <summary>
/// Invalid {0}, {1} or {2} length.
/// </summary>
Expand Down
Loading