??????github???濴?????????BenchmarkDotNet????????£? ????????????????????????????????
??????????StopWatch?????BenchmarkDotNet???? http://www.cnblogs.com/rader/p/4920862.html
????????????????blog???????????????????????????????????????????????
?????????????????????????????????ò?????????????XUnit?????????????
????Nuget: https://www.nuget.org/packages/BenchmarkDotNet/
????Project Site: https://github.com/PerfDotNet/BenchmarkDotNet
???????BenchmarkDotNet
????PM> Install-Package BenchmarkDotNet
????????
public class Md5VsSha256
{
private const int N = 10000;
private readonly byte[] data;
private readonly SHA256 sha256 = SHA256.Create();
private readonly MD5 md5 = MD5.Create();
public Md5VsSha256()
{
data = new byte[N];
new Random(42).NextBytes(data);
}
[Benchmark]
public byte[] Sha256()
{
return sha256.ComputeHash(data);
}
[Benchmark]
public byte[] Md5()
{
return md5.ComputeHash(data);
}
}
????????
????var summary = BenchmarkRunner.Run<Md5VsSha256>();
???????
// * Summary *
BenchmarkDotNet=v0.9.1.0
OS=Microsoft Windows NT 6.1.7601 Service Pack 1
Processor=Intel(R) Core(TM) i5-4440 CPU @ 3.10GHz?? ProcessorCount=4
Frequency=3020400 ticks?? Resolution=331.0820 ns
HostCLR=MS.NET 4.0.30319.42000?? Arch=64-bit RELEASE [RyuJIT]
Type=BenchmarkTest  Mode=Throughput
Method |     Median |    StdDev |
------- |----------- |---------- |
xxx | 58.4725 ns | 0.5935 ns |
// ***** BenchmarkRunner: End *****