forked from ServiceStack/ServiceStack.Text
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
70 lines (62 loc) · 2.16 KB
/
Program.cs
File metadata and controls
70 lines (62 loc) · 2.16 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Linq;
using System.Security.Cryptography;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Attributes.Columns;
using BenchmarkDotNet.Attributes.Exporters;
using BenchmarkDotNet.Attributes.Jobs;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Reports;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Validators;
namespace ServiceStack.Text.Benchmarks
{
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() => sha256.ComputeHash(data);
[Benchmark]
public byte[] Md5() => md5.ComputeHash(data);
}
public class AllowNonOptimized : ManualConfig
{
public AllowNonOptimized()
{
Add(JitOptimizationsValidator.DontFailOnError); // ALLOW NON-OPTIMIZED DLLS
Add(DefaultConfig.Instance.GetLoggers().ToArray()); // manual config has no loggers by default
Add(DefaultConfig.Instance.GetExporters().ToArray()); // manual config has no exporters by default
Add(DefaultConfig.Instance.GetColumnProviders().ToArray()); // manual config has no columns by default
}
}
public class Program
{
public static void Main(string[] args)
{
#if true
Summary summary;
// summary = BenchmarkRunner.Run<Md5VsSha256>();
// summary = BenchmarkRunner.Run<MemoryProviderBenchmarks>();
// summary = BenchmarkRunner.Run<MemoryDecimalBenchmarks>();
// summary = BenchmarkRunner.Run<MemoryIntegerBenchmarks>();
summary = BenchmarkRunner.Run<BookShelf10000BooksBenchmarks>();
#else
var test = new BookShelf10000BooksBenchmarks();
test.Setup();
for (var i = 0; i < 200; i++)
{
// test.DeserializeFromString();
test.SerializeToString();
}
#endif
}
}
}