-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
119 lines (103 loc) · 4.1 KB
/
Program.cs
File metadata and controls
119 lines (103 loc) · 4.1 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#if DEBUG
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Running;
#endif
using System.Diagnostics;
using System.Runtime.InteropServices;
class Program
{
public static string ?TotalRunTime;
static void Main(string[] args)
{
ConsoleInfo.GetAppInfo();
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
MacOSHelper.DisplayMacInfo();
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
DisplayWindowsInfo();
}
Console.ForegroundColor = ConsoleColor.White;
Console.Write("Continue to benchmark? (y/n): ");
var input = Console.ReadLine();
if (string.Equals(input, "y", StringComparison.OrdinalIgnoreCase))
{
RunBenchmark();
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
// Prevent app exit on macOS
Console.WriteLine("Press Enter to exit to exit...");
Console.ReadLine();
}
}
static void DisplayWindowsInfo()
{
ConsoleSpinner.Start();
WindowsHelper.DisplayCpuInfo();
WindowsHelper.DisplayRamInfo();
DxGpuHelper.DisplayGpuInfo();
ConsoleSpinner.Stop();
}
static void RunBenchmark()
{
Console.WriteLine("Choose a benchmark to run:");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("1. Hashing Benchmark");
Console.WriteLine("2. Encryption Benchmark");
Console.WriteLine("3. CPU Prime Computation");
Console.WriteLine("4. CPU Matrix Multiplication");
Console.WriteLine("5. Memory Bandwidth");
Console.WriteLine("6. Run all benchmarks");
#if DEBUG
Console.WriteLine("7. Debug Mode");
Console.WriteLine("8. Test Reults Export");
#endif
Console.ForegroundColor = ConsoleColor.White;
Console.Write("Enter the number of your choice: ");
List<string> results = new();
string? choice = Console.ReadLine();
var EncrypBenchmark = new EncryptionBenchmark();
var HashBenchmark = new HashingBenchmark();
var MMUL = new MatrixMultiplicationBenchmark();
var MemoryBenchmark = new MemoryBenchmark();
var benchmarkActions = new Dictionary<string, Action>
{
["1"] = () => results.Add(HashBenchmark.CombinedHashingExport()),
["2"] = () => results.Add(EncrypBenchmark.RunEncryptBenchmark()),
["3"] = () => results.Add(CPUBenchmark.CpuPrimeCompute()),
["4"] = () => results.Add(MMUL.MultiplyMatrix()),
["5"] = () => results.Add(MemoryBenchmark.MTMemBandwidth()),
["6"] = () =>
{
results.AddRange(HashBenchmark.CombinedHashingExport(), EncrypBenchmark.RunEncryptBenchmark(),
CPUBenchmark.CpuPrimeCompute(), MMUL.MultiplyMatrix(), MemoryBenchmark.MTMemBandwidth());
},
#if DEBUG
["7"] = () => BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(new[] { "Benchmarks" }, new DebugInProcessConfig()),
["8"] = () => BenchmarkExporter.TestExportResults()
#endif
};
if (choice != null && benchmarkActions.TryGetValue(choice, out Action? benchmarkAction))
{
Console.WriteLine("-----------------------------------------------------------");
Stopwatch stopwatch = Stopwatch.StartNew();
benchmarkAction?.Invoke();
stopwatch.Stop();
Console.ForegroundColor = ConsoleColor.DarkCyan;
Console.WriteLine($"Total Execution Time: {stopwatch.ElapsedMilliseconds} ms.");
GcHelper.MemoryCleanUp();
Program.TotalRunTime = stopwatch.ElapsedMilliseconds.ToString();
Console.ForegroundColor = ConsoleColor.Cyan;
BenchmarkExporter.ExportResults("BenchmarkResults.txt", results.ToArray());
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Press Enter to exit...");
Console.ReadLine();
}
else
{
Console.WriteLine("Invalid choice.");
}
}
}