Skip to content

Instantly share code, notes, and snippets.

@dmitry-ra
Created January 30, 2021 08:26
Show Gist options
  • Save dmitry-ra/9522673bae4489ed6cd11d3f50680277 to your computer and use it in GitHub Desktop.
Save dmitry-ra/9522673bae4489ed6cd11d3f50680277 to your computer and use it in GitHub Desktop.
using System;
using BenchmarkDotNet.Attributes;
namespace Base32Benchmarks
{
// <ItemGroup>
// <PackageReference Include = "Albireo.Base32" Version="1.2.0" />
// <PackageReference Include = "BenchmarkDotNet" Version="0.12.1" />
// <PackageReference Include = "deniszykov.BaseN" Version="3.0.0" />
// <PackageReference Include = "SimpleBase" Version="3.0.2" />
// <PackageReference Include = "Wiry.Base32" Version="1.1.1" />
// </ItemGroup>
public class Base32DecodeBenchmarks
{
private const int N = 20 * 1024 * 1024;
private readonly string _base32Text;
private readonly string _base64Text;
public Base32DecodeBenchmarks()
{
var data = new byte[N];
new Random(42).NextBytes(data);
_base32Text = deniszykov.BaseN.Base32Convert.ToString(data);
_base64Text = deniszykov.BaseN.Base64Convert.ToString(data);
}
[Benchmark(Baseline = true)]
public void System_Convert_FromBase64String()
{
_ = Convert.FromBase64String(_base64Text);
}
[Benchmark]
public void BaseN_Base64Convert_ToBytes()
{
_ = deniszykov.BaseN.Base64Convert.ToBytes(_base64Text);
}
[Benchmark]
public void BaseN_Base32Convert_ToBytes()
{
_ = deniszykov.BaseN.Base32Convert.ToBytes(_base32Text);
}
[Benchmark]
public void Wiry_Base32Encoding_Standard_ToBytes()
{
_ = Wiry.Base32.Base32Encoding.Standard.ToBytes(_base32Text);
}
[Benchmark]
public void SimpleBase_Base32_Rfc4648_Decode()
{
_ = SimpleBase.Base32.Rfc4648.Decode(_base32Text);
}
[Benchmark]
public void Albireo_Base32_Decode()
{
_ = Albireo.Base32.Base32.Decode(_base32Text);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment