BenchmarkDotNet=v0.11.3, OS=Windows 10.0.17763.134 (1809/October2018Update/Redstone5)
Intel Core i9-9900K CPU 3.60GHz, 1 CPU, 16 logical and 8 physical cores
.NET Core SDK=2.2.100
[Host] : .NET Core 2.2.0 (CoreCLR 4.6.27110.04, CoreFX 4.6.27110.04), 64bit RyuJIT
DefaultJob : .NET Core 2.2.0 (CoreCLR 4.6.27110.04, CoreFX 4.6.27110.04), 64bit RyuJIT
Method |
Iterations |
Mean |
Error |
StdDev |
Ratio |
Rfc2898DeriveBytesSHA512 |
1000 |
697.2 us |
4.5298 us |
4.2372 us |
1.00 |
KeyDerivationPBKDF2SHA512 |
1000 |
566.9 us |
0.1305 us |
0.1157 us |
0.81 |
|
|
|
|
|
|
Rfc2898DeriveBytesSHA512 |
10000 |
6,884.2 us |
6.0406 us |
5.6504 us |
1.00 |
KeyDerivationPBKDF2SHA512 |
10000 |
5,656.8 us |
0.6831 us |
0.5704 us |
0.82 |
|
|
|
|
|
|
Rfc2898DeriveBytesSHA512 |
100000 |
69,023.7 us |
435.1230 us |
407.0143 us |
1.00 |
KeyDerivationPBKDF2SHA512 |
100000 |
56,521.2 us |
13.3939 us |
12.5287 us |
0.82 |
BenchmarkDotNet=v0.11.3, OS=Windows 10.0.17763.134 (1809/October2018Update/Redstone5)
Intel Core i9-9900K CPU 3.60GHz, 1 CPU, 16 logical and 8 physical cores
.NET Core SDK=3.0.100-preview-009812
[Host] : .NET Core 3.0.0-preview-27122-01 (CoreCLR 4.6.27121.03, CoreFX 4.7.18.57103), 64bit RyuJIT
DefaultJob : .NET Core 3.0.0-preview-27122-01 (CoreCLR 4.6.27121.03, CoreFX 4.7.18.57103), 64bit RyuJIT
Method |
Iterations |
Mean |
Error |
StdDev |
Ratio |
Rfc2898DeriveBytesSHA512 |
1000 |
636.6 us |
3.086 us |
2.735 us |
1.00 |
KeyDerivationPBKDF2SHA512 |
1000 |
543.0 us |
3.905 us |
3.462 us |
0.85 |
|
|
|
|
|
|
Rfc2898DeriveBytesSHA512 |
10000 |
6,346.5 us |
21.671 us |
20.271 us |
1.00 |
KeyDerivationPBKDF2SHA512 |
10000 |
5,375.3 us |
16.912 us |
15.819 us |
0.85 |
|
|
|
|
|
|
Rfc2898DeriveBytesSHA512 |
100000 |
63,773.5 us |
562.408 us |
498.560 us |
1.00 |
KeyDerivationPBKDF2SHA512 |
100000 |
53,815.7 us |
208.178 us |
194.730 us |
0.84 |
public class HashBenchmark
{
[Params(1000, 10000, 100000)]
public int Iterations { get; set; }
private static readonly byte[] _password = Encoding.UTF8.GetBytes("Hello World");
private static readonly byte[] _salt = GenerateSalt();
private static byte[] GenerateSalt()
{
using (var random = new RNGCryptoServiceProvider())
{
var result = new byte[64];
random.GetBytes(result);
return result;
}
}
[Benchmark(Baseline = true)]
public byte[] Rfc2898DeriveBytesSHA512()
{
var rfc = new Rfc2898DeriveBytes(_password, _salt, Iterations, HashAlgorithmName.SHA512);
return rfc.GetBytes(64);
}
[Benchmark]
public byte[] KeyDerivationPBKDF2SHA512()
{
var key = KeyDerivation.Pbkdf2("Hello World", _salt, KeyDerivationPrf.HMACSHA512, Iterations, 512 / 8);
return key;
}
}