-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathProgram.cs
53 lines (43 loc) · 1.27 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Made by Benjamin Abt - https://github.com/BenjaminAbt
using System.Security.Cryptography;
using System.Text;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
BenchmarkRunner.Run<Benchmark>();
[MemoryDiagnoser]
[SimpleJob(RuntimeMoniker.Net70)] // PGO enabled by default
[SimpleJob(RuntimeMoniker.Net80)]
[SimpleJob(RuntimeMoniker.Net90, baseline: true)]
[HideColumns(Column.Job)]
public class Benchmark
{
private readonly byte[] _sampleData;
public Benchmark()
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
Encoding winEncoding1252 = Encoding.GetEncoding(1252);
string sample = new('a', 1000);
_sampleData = winEncoding1252.GetBytes(sample);
}
[Benchmark]
public byte[] Create()
{
using SHA512 sha512 = SHA512.Create();
return sha512.ComputeHash(_sampleData);
}
private static readonly SHA512 s_sha512 = SHA512.Create(); // IDisposable
[Benchmark]
public byte[] Lock()
{
byte[] data;
lock (s_sha512)
{
data = s_sha512.ComputeHash(_sampleData);
}
return data;
}
[Benchmark]
public byte[] HashData() => SHA512.HashData(_sampleData);
}