-
-
Save vcsjones/78a4d099902ba5e172a6e374281638ce to your computer and use it in GitHub Desktop.
HMAC benchmarks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>net6.0</TargetFramework> | |
<RootNamespace>benchmark_scratch</RootNamespace> | |
<ImplicitUsings>enable</ImplicitUsings> | |
<Nullable>enable</Nullable> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="BenchmarkDotNet" Version="0.13.1" /> | |
</ItemGroup> | |
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Security.Cryptography; | |
using BenchmarkDotNet.Attributes; | |
using BenchmarkDotNet.Running; | |
BenchmarkRunner.Run<HmacBenchMark>(); | |
[MemoryDiagnoser] | |
public class HmacBenchMark | |
{ | |
private readonly byte[] _hmacKey = RandomNumberGenerator.GetBytes(32); | |
private readonly byte[] _hmacData = RandomNumberGenerator.GetBytes(32); | |
[Benchmark] | |
public byte[] HmacCreateDispose() | |
{ | |
using (HMACSHA1 hmac = new HMACSHA1(_hmacKey)) | |
{ | |
return hmac.ComputeHash(_hmacData); | |
} | |
} | |
[Benchmark] | |
public byte[] HmacOneShot() | |
{ | |
return HMACSHA1.HashData(_hmacKey, _hmacData); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment