diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6ceeb45..fa1391e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -77,6 +77,6 @@ jobs: - name: Create Release uses: ncipollo/release-action@v1.14.0 with: - tag: v1.5.0 + tag: v1.5.1 artifacts: "artifacts/**" artifactContentType: application/octet-stream \ No newline at end of file diff --git a/.gitignore b/.gitignore index 1a02111..782291d 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,9 @@ *.userosscache *.sln.docstates +# Generated results file +BenchmarkResults.txt + # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs diff --git a/Benchmark.csproj b/Benchmark.csproj index 9d2a567..f23ab74 100644 --- a/Benchmark.csproj +++ b/Benchmark.csproj @@ -3,7 +3,7 @@ Exe net9.0 - 1.5.0 + 1.5.1 $([System.DateTime]::Now.ToString('yyyyMMddHH')) Dom enable diff --git a/Benchmarks.cs b/Benchmarks/Benchmarks.cs similarity index 55% rename from Benchmarks.cs rename to Benchmarks/Benchmarks.cs index b0d43a9..e662767 100644 --- a/Benchmarks.cs +++ b/Benchmarks/Benchmarks.cs @@ -1,22 +1,25 @@ -using BenchmarkDotNet.Attributes; -using System; -using System.Diagnostics; -using System.Reflection; -using System.Runtime.InteropServices; -using System.Threading; +using System.Diagnostics; using System.Security.Cryptography; +using System.Buffers; public class HashingBenchmark { - private const int N = 2000000000; + private int N; private readonly byte[] data; - private readonly SHA256 sha256 = SHA256.Create(); private readonly SHA512 sha512 = SHA512.Create(); private readonly MD5 md5 = MD5.Create(); public HashingBenchmark() { + if (Debugger.IsAttached) + { + N = 1000000000; + } + else + { + N = 2000000000; + } data = new byte[N]; new Random(42).NextBytes(data); } @@ -27,10 +30,10 @@ public HashingBenchmark() public byte[] Md5() => md5.ComputeHash(data); - public void CombinedHashing() + public string CombinedHashingExport() { Console.ForegroundColor = ConsoleColor.White; - Console.WriteLine("Running Hashing operation..."); + Console.WriteLine($"Running Hash on SHA256, SHA512, MD5... Hashing {N / 1_000_000_000} GB..."); Stopwatch stopwatch = Stopwatch.StartNew(); ConsoleSpinner.Start(); @@ -41,17 +44,20 @@ public void CombinedHashing() stopwatch.Stop(); ConsoleSpinner.Stop(); Console.ForegroundColor = ConsoleColor.Cyan; - Console.WriteLine($"Hasing completed in {stopwatch.ElapsedMilliseconds} ms."); + Console.WriteLine($"Hashing completed in {stopwatch.ElapsedMilliseconds} ms."); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("-----------------------------------------------------------"); + + string result = $"Hashing Benchmark: {stopwatch.ElapsedMilliseconds} ms"; + return result; } } public class EncryptionBenchmark { - private const long TotalSize = 16L * 1_000_000_000; // 16GB + private long TotalSize; private const int ChunkSize = 100_000_000; // 100MB per operation - private const int Iterations = (int)(TotalSize / ChunkSize); // Number of chunks needed + private int Iterations; private readonly byte[] dataChunk; private readonly byte[] key; private readonly byte[] iv; @@ -59,6 +65,15 @@ public class EncryptionBenchmark public EncryptionBenchmark() { + if (Debugger.IsAttached) + { + TotalSize = 1L * 1_000_000_000; // 1GB + } + else + { + TotalSize = 16L * 1_000_000_000; // 16GB + } + Iterations = (int)(TotalSize / ChunkSize); aes = Aes.Create(); aes.KeySize = 256; aes.GenerateKey(); @@ -68,7 +83,7 @@ public EncryptionBenchmark() iv = aes.IV; dataChunk = new byte[ChunkSize]; - new Random().NextBytes(dataChunk); // Generate random data once + new Random().NextBytes(dataChunk); } public byte[] AesEncrypt(byte[] data) @@ -83,9 +98,9 @@ public byte[] AesDecrypt(byte[] encryptedData) return decryptor.TransformFinalBlock(encryptedData, 0, encryptedData.Length); } - public void RunEncryptBenchmark() + public string RunEncryptBenchmark() { - int threadCount = Environment.ProcessorCount; // Match CPU core count + int threadCount = Environment.ProcessorCount; Console.ForegroundColor = ConsoleColor.White; Console.WriteLine($"Running AES-256 Encryption... processing {TotalSize / 1_000_000_000} GB with {threadCount} threads..."); @@ -107,15 +122,28 @@ public void RunEncryptBenchmark() Console.WriteLine($"Encryption completed in {stopwatch.ElapsedMilliseconds} ms."); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("-----------------------------------------------------------"); + + string result = $"Encryption Benchmark: {stopwatch.ElapsedMilliseconds} ms"; + return result; } } class CPUBenchmark { - public static void CpuPrimeCompute() + public static string CpuPrimeCompute() { + int iterations; + + if (Debugger.IsAttached) + { + iterations = 100_000_000; + } + else + { + iterations = 400_000_000; // Default value if not debugging + } + int taskCount = Environment.ProcessorCount; - int iterations = 400_000_000; int iterationsPerThread = iterations / taskCount; Console.ForegroundColor = ConsoleColor.White; @@ -140,6 +168,9 @@ public static void CpuPrimeCompute() Console.WriteLine($"Prime compute completed in {stopwatch.ElapsedMilliseconds} ms."); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("-----------------------------------------------------------"); + + string result = $"Prime Compute Benchmark: {stopwatch.ElapsedMilliseconds} ms"; + return result; } private static int ComputePrimes(int limit) @@ -168,13 +199,21 @@ private static bool IsPrime(int number) class MatrixMultiplicationBenchmark { - private const int N = 2048; // Matrix size + private int N; // Matrix size private readonly double[,] matrixA; private readonly double[,] matrixB; private readonly double[,] result; public MatrixMultiplicationBenchmark() { + if (Debugger.IsAttached) + { + N = 1024; + } + else + { + N = 2048; + } matrixA = new double[N, N]; matrixB = new double[N, N]; result = new double[N, N]; @@ -190,7 +229,7 @@ public MatrixMultiplicationBenchmark() } } - public void MultiplyMatrix() + public string MultiplyMatrix() { Console.ForegroundColor = ConsoleColor.White; Console.WriteLine($"Running Matrix Multiplication with {Environment.ProcessorCount} threads..."); @@ -221,5 +260,88 @@ public void MultiplyMatrix() Console.WriteLine($"Matrix multiplication completed in {stopwatch.ElapsedMilliseconds} ms."); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("-----------------------------------------------------------"); + + string benchResult = $"Matrix Multiplication Benchmark: {stopwatch.ElapsedMilliseconds} ms"; + return benchResult; + } +} + +// WIP +public class MemoryBenchmark +{ + public string MTMemBandwidth() + { + Console.ForegroundColor = ConsoleColor.White; + Console.WriteLine("Running Memory Bandwidth Benchmark..."); + + uint[] data = new uint[10000000 * 32]; + List<(long Sum, double Bandwidth)> AllResults = new(); + (long Sum, double Bandwidth) BestResult; + + for (int j = 0; j < 15; j++) + { + long totalSum = 0; + var sw = Stopwatch.StartNew(); + int chunkSize = data.Length / Environment.ProcessorCount; + object lockObj = new object(); + + Parallel.For(0, Environment.ProcessorCount, threadId => + { + int start = threadId * chunkSize; + int end = (threadId == Environment.ProcessorCount - 1) ? data.Length : start + chunkSize; + uint localSum = 0; + + for (int i = start; i < end; i += 64) + { + localSum += data[i] + data[i + 16] + data[i + 32] + data[i + 48]; + } + + lock (lockObj) + { + totalSum += localSum; + } + }); + + sw.Stop(); + long dataSize = data.Length * 4; + double bandwidth = dataSize / sw.Elapsed.TotalSeconds / (1024 * 1024 * 1024); + + //Console.WriteLine("{1:0.000} GB/s", totalSum, bandwidth); + AllResults.Add((totalSum, bandwidth)); + } + + BestResult = AllResults.OrderByDescending(x => x.Bandwidth).First(); // Sort for highest + Console.WriteLine($"Memory Bandwidth: {BestResult.Bandwidth:0.000} GB/s"); + + string benchResult = $"Memory Bandwidth: {BestResult.Bandwidth:0.000} GB/s"; + return benchResult; + } + + public string STMemBandwidth() + { + List<(long Sum, double Bandwidth)> AllResults = new(); + (long Sum, double Bandwidth) BestResult; + uint[] data = new uint[10000000 * 32]; + for (int j = 0; j < 15; j++) + { + long totalSum = 0; + uint sum = 0; + var sw = Stopwatch.StartNew(); + for (uint i = 0; i < data.Length; i += 64) + { + sum += data[i] + data[i + 16] + data[i + 32] + data[i + 48]; + } + sw.Stop(); + long dataSize = data.Length * 4; + double bandwidth = dataSize / sw.Elapsed.TotalSeconds / (1024 * 1024 * 1024); + Console.WriteLine("{0} {1:0.000} GB/s", sum, dataSize / sw.Elapsed.TotalSeconds / (1024 * 1024 * 1024)); + AllResults.Add((totalSum, bandwidth)); + } + + BestResult = AllResults.OrderByDescending(x => x.Bandwidth).First(); // Sort for highest + Console.WriteLine($"Memory Bandwidth: {BestResult.Sum} {BestResult.Bandwidth:0.000} GB/s"); + + string benchResult = $"Memory Bandwidth: {BestResult.Sum} {BestResult.Bandwidth:0.000} GB/s"; + return benchResult; } } \ No newline at end of file diff --git a/OldBenchmark.cs b/Benchmarks/OldBenchmark.cs similarity index 96% rename from OldBenchmark.cs rename to Benchmarks/OldBenchmark.cs index 0aa0286..2561872 100644 --- a/OldBenchmark.cs +++ b/Benchmarks/OldBenchmark.cs @@ -1,13 +1,7 @@ using System.Diagnostics; using System.Runtime.InteropServices; using System.Security.Cryptography; -using System.Threading; -using System.Timers; using BenchmarkDotNet.Attributes; -using BenchmarkDotNet.Running; -using NvAPIWrapper; -using NvAPIWrapper.Display; -using NvAPIWrapper.GPU; using SharpDX.Direct3D11; using SharpDX.DXGI; using Device = SharpDX.Direct3D11.Device; diff --git a/Helpers/GpuHelper.cs b/Helpers/GpuHelper.cs new file mode 100644 index 0000000..8889552 --- /dev/null +++ b/Helpers/GpuHelper.cs @@ -0,0 +1,170 @@ +using System.Management; +using System.Runtime.InteropServices; +using NvAPIWrapper; +using NvAPIWrapper.GPU; +using SharpDX.DXGI; + +class DxGpuHelper +{ + public static async void DisplayGpuInfo() + { + try + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + using var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_VideoController"); + bool hasNvidiaGPU = PhysicalGPU.GetPhysicalGPUs().Any(gpu => gpu.FullName.Contains("NVIDIA")); + + if (hasNvidiaGPU) + { + NVIDIA.Initialize(); + var nvidiaGPUs = PhysicalGPU.GetPhysicalGPUs(); + var driver = NVIDIA.DriverVersion; + var driverbranch = NVIDIA.DriverBranchVersion; + + foreach (var gpu in nvidiaGPUs) + { + Console.ForegroundColor = ConsoleColor.Cyan; + Console.WriteLine("[GPU Information]"); + + Console.ForegroundColor = ConsoleColor.White; + Console.Write("GPU Type: "); + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine(gpu.GPUType); + + Console.ForegroundColor = ConsoleColor.White; + Console.Write("Name: "); + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine(gpu.FullName); + + Console.ForegroundColor = ConsoleColor.White; + Console.Write("GPU Core: "); + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine(gpu.ArchitectInformation.ShortName); + + Console.ForegroundColor = ConsoleColor.White; + Console.Write("Shaders: "); + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine(gpu.ArchitectInformation.NumberOfCores); + + var graphicsClockMHz = gpu.BoostClockFrequencies.GraphicsClock.Frequency / 1000; + Console.ForegroundColor = ConsoleColor.White; + Console.Write("GPU Core Speed: "); + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine("{0} MHz", graphicsClockMHz); + + Console.ForegroundColor = ConsoleColor.White; + Console.Write("VRAM: "); + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine("{0} MB", gpu.MemoryInformation.DedicatedVideoMemoryInkB / 1024); + + Console.ForegroundColor = ConsoleColor.White; + Console.Write("VRAM Type: "); + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine(gpu.MemoryInformation.RAMType); + + var memoryClockMHz = gpu.BoostClockFrequencies.MemoryClock.Frequency / 1000; + Console.ForegroundColor = ConsoleColor.White; + Console.Write("VRAM Frequency: "); + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine("{0} MHz", memoryClockMHz); + } + } + + foreach (var item in searcher.Get()) + { + var manufacturer = item["AdapterCompatibility"]?.ToString(); + if (manufacturer == null) continue; + + if (manufacturer.ToLower().Contains("nvidia")) continue; + + if (manufacturer.ToLower().Contains("intel") || manufacturer.ToLower().Contains("amd")) + { + Console.ForegroundColor = ConsoleColor.Magenta; + Console.WriteLine("-----------------------------------------------------------"); + + Console.ForegroundColor = ConsoleColor.Cyan; + Console.WriteLine("[Integrated GPU]"); + + Console.ForegroundColor = ConsoleColor.White; + Console.Write("Name: "); + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine(item["Name"]); + + Console.ForegroundColor = ConsoleColor.White; + Console.Write("Manufacturer: "); + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine(manufacturer); + + Console.ForegroundColor = ConsoleColor.White; + Console.Write("Driver Version: "); + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine(item["DriverVersion"]); + + Console.ForegroundColor = ConsoleColor.White; + Console.Write("VRAM: "); + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine("{0} MB", Convert.ToUInt64(item["AdapterRAM"]) / (1024 * 1024)); + + Console.ForegroundColor = ConsoleColor.Magenta; + Console.WriteLine("-----------------------------------------------------------"); + } + else + { + if (manufacturer.ToLower().Contains("advanced micro devices")) + { + manufacturer = "AMD"; + } + + if (!hasNvidiaGPU) + { + using var factory = new Factory1(); + using var adapter = factory.GetAdapter(0); + var desc = adapter.Description; + + Console.ForegroundColor = ConsoleColor.White; + Console.Write("Name: "); + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine(desc.Description); + + Console.ForegroundColor = ConsoleColor.White; + Console.Write("Manufacturer: "); + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine(manufacturer); + + Console.ForegroundColor = ConsoleColor.White; + Console.Write("Driver Version: "); + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine(item["DriverVersion"]); + + if (desc.DedicatedVideoMemory == 0) + { + Console.WriteLine("No dedicated GPU memory found"); + } + else + { + Console.ForegroundColor = ConsoleColor.White; + Console.Write("VRAM: "); + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine("{0} MB", desc.DedicatedVideoMemory / (1024 * 1024)); + + Console.ForegroundColor = ConsoleColor.White; + Console.Write("Shared Memory: "); + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine("{0} MB", desc.SharedSystemMemory / (1024 * 1024)); + } + + Console.ForegroundColor = ConsoleColor.Magenta; + Console.WriteLine("-----------------------------------------------------------"); + } + } + } + } + } + catch (Exception ex) + { + Console.WriteLine("An error occurred while retrieving GPU information: " + ex.Message); + } + await Task.Delay(500); + } +} \ No newline at end of file diff --git a/Helpers.cs b/Helpers/Helpers.cs similarity index 75% rename from Helpers.cs rename to Helpers/Helpers.cs index ef5b528..d0046ab 100644 --- a/Helpers.cs +++ b/Helpers/Helpers.cs @@ -1,11 +1,5 @@ -using BenchmarkDotNet.Attributes; -using System; using System.Diagnostics; using System.Reflection; -using System.Runtime.InteropServices; -using System.Threading; -using System.Security.Cryptography; - class ConsoleInfo { public static void GetAppInfo() @@ -31,6 +25,16 @@ public static void GetAppInfo() Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine("-----------------------------------------------------------"); } + + public static string Version() + { + Assembly? assembly = Assembly.GetEntryAssembly(); + AssemblyName? assemblyName = assembly?.GetName(); + Version? version = assemblyName?.Version; + string? fileVersion = assembly?.GetCustomAttribute()?.Version; + + return $"v{version} ({fileVersion})"; + } } class ConsolePasswordHelper @@ -90,30 +94,4 @@ static string ReadPassword() Console.WriteLine(); return password; } -} -class MacOSPowerMetrics -{ - static void DisplayMacInfoByPowermetrics() - { - Console.ForegroundColor = ConsoleColor.Cyan; - var startInfo = new ProcessStartInfo - { - FileName = "/usr/bin/powermetrics", - Arguments = "sudo powermetrics --samplers cpu_power,gpu_power -n 1s", - RedirectStandardOutput = true, - UseShellExecute = false - }; - - var process = new Process { StartInfo = startInfo }; - process.Start(); - - while (!process.StandardOutput.EndOfStream) - { - string? line = process.StandardOutput.ReadLine(); - if (line != null) - { - Console.WriteLine(line); - } - } - } } \ No newline at end of file diff --git a/Helpers/MacOSHelper.cs b/Helpers/MacOSHelper.cs new file mode 100644 index 0000000..ca290f5 --- /dev/null +++ b/Helpers/MacOSHelper.cs @@ -0,0 +1,60 @@ +using System.Diagnostics; + +class MacOSHelper +{ + public static void DisplayMacInfo() + { + Console.ForegroundColor = ConsoleColor.Cyan; + var startInfo = new ProcessStartInfo + { + FileName = "/usr/sbin/system_profiler", + Arguments = "SPSoftwareDataType SPHardwareDataType SPMemoryDataType SPDisplaysDataType", + RedirectStandardOutput = true, + UseShellExecute = false + }; + + var process = new Process { StartInfo = startInfo }; + process.Start(); + + var exclusions = new List + { + "Serial Number (system):", "Hardware UUID:", "Model Number:", "Provisioning UDID:", "Boot Volume:", + "Boot Mode:", "Computer Name:", "User Name:", "Kernel Version: Darwin", "Secure Virtual Memory: Enabled", + "System Integrity Protection: Enabled", "Time since boot:", "System Firmware Version:", "OS Loader Version:", + "Activation Lock Status:", "Bus: Built-In", "Vendor:" + }; + + while (!process.StandardOutput.EndOfStream) + { + string? line = process.StandardOutput.ReadLine(); + if (line != null && !exclusions.Any(line.Contains)) + { + Console.WriteLine(line); + } + } + } + + static void Powermetrics() + { + Console.ForegroundColor = ConsoleColor.Cyan; + var startInfo = new ProcessStartInfo + { + FileName = "/usr/bin/powermetrics", + Arguments = "sudo powermetrics --samplers cpu_power,gpu_power -n 1s", + RedirectStandardOutput = true, + UseShellExecute = false + }; + + var process = new Process { StartInfo = startInfo }; + process.Start(); + + while (!process.StandardOutput.EndOfStream) + { + string? line = process.StandardOutput.ReadLine(); + if (line != null) + { + Console.WriteLine(line); + } + } + } +} \ No newline at end of file diff --git a/Helpers/WindowsHelper.cs b/Helpers/WindowsHelper.cs new file mode 100644 index 0000000..27d04d1 --- /dev/null +++ b/Helpers/WindowsHelper.cs @@ -0,0 +1,133 @@ +using System.Management; +using System.Runtime.InteropServices; +using Hardware.Info; + +class WindowsHelper +{ + public static async void DisplayCpuInfo() + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + using var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Processor"); + foreach (var item in searcher.Get()) + { + try + { + Console.ForegroundColor = ConsoleColor.Cyan; + Console.WriteLine("[CPU Information]"); + + Console.ForegroundColor = ConsoleColor.White; + Console.Write("Processor Name: "); + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine(item["Name"]); + + Console.ForegroundColor = ConsoleColor.White; + Console.Write("Cores: "); + Console.ForegroundColor = ConsoleColor.Yellow; + Console.Write($"{item["NumberOfCores"]}"); + + Console.ForegroundColor = ConsoleColor.White; + Console.Write(", Threads: "); + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine(item["NumberOfLogicalProcessors"]); + + Console.ForegroundColor = ConsoleColor.White; + Console.Write("Base Frequency: "); + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine("{0}MHz", item["MaxClockSpeed"]); + + IHardwareInfo hardwareInfo = new HardwareInfo(); + hardwareInfo.RefreshAll(); + Console.ForegroundColor = ConsoleColor.White; + Console.Write("Current Frequency: "); + Console.ForegroundColor = ConsoleColor.Yellow; + + foreach (var cpu in hardwareInfo.CpuList) + { + Console.WriteLine("{0}MHz", cpu.CurrentClockSpeed); + } + + Console.ForegroundColor = ConsoleColor.White; + Console.Write("L2 Cache: "); + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine("{0}MB", Convert.ToInt64(item["L2CacheSize"]) / 1024); + + Console.ForegroundColor = ConsoleColor.White; + Console.Write("L3 Cache: "); + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine("{0}MB", Convert.ToInt64(item["L3CacheSize"]) / 1024); + + Console.ForegroundColor = ConsoleColor.White; + Console.Write("Voltage: "); + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine("{0}V", item["CurrentVoltage"]); + + Console.ForegroundColor = ConsoleColor.Magenta; + Console.WriteLine("-----------------------------------------------------------"); + } + catch (Exception ex) + { + Console.WriteLine("An error occurred while retrieving CPU information: " + ex.Message); + } + await Task.Delay(500); + } + } + } + + public static async void DisplayRamInfo() + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + using var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMemory"); + try + { + long totalCapacity = 0; + string? manufacturer = null; + foreach (ManagementObject item in searcher.Get().Cast()) + { + totalCapacity += Convert.ToInt64(item["Capacity"]); + manufacturer = item["Manufacturer"]?.ToString()?.Trim(); + } + + Console.ForegroundColor = ConsoleColor.Cyan; + Console.WriteLine("[Memory Information]"); + + Console.ForegroundColor = ConsoleColor.White; + Console.Write("Total Capacity: "); + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine("{0} GB", totalCapacity / (1024 * 1024 * 1024)); + + Console.ForegroundColor = ConsoleColor.White; + Console.Write("Manufacturer: "); + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine(manufacturer); + + searcher.Query = new ObjectQuery("SELECT * FROM Win32_PhysicalMemory"); + int slotNumber = 1; + foreach (ManagementObject item in searcher.Get().Cast()) + { + Console.WriteLine(); + Console.ForegroundColor = ConsoleColor.White; + Console.WriteLine("(Slot {0})", slotNumber++); + + Console.Write("Speed: "); + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine("{0} MHz", item["Speed"]); + + Console.ForegroundColor = ConsoleColor.White; + Console.Write("Capacity: "); + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine("{0} GB", Convert.ToInt64(item["Capacity"]) / (1024 * 1024 * 1024)); + } + + Console.ForegroundColor = ConsoleColor.Magenta; + Console.WriteLine("-----------------------------------------------------------"); + } + catch (Exception ex) + { + Console.WriteLine("An error occurred while retrieving memory information: " + ex.Message); + } + await Task.Delay(500); + } + } +} \ No newline at end of file diff --git a/macos_output.png b/Media/macos_output.png similarity index 100% rename from macos_output.png rename to Media/macos_output.png diff --git a/macos_results.png b/Media/macos_results.png similarity index 100% rename from macos_results.png rename to Media/macos_results.png diff --git a/resultOutput.png b/Media/resultOutput.png similarity index 100% rename from resultOutput.png rename to Media/resultOutput.png diff --git a/winX64output.png b/Media/winX64output.png similarity index 100% rename from winX64output.png rename to Media/winX64output.png diff --git a/Program.cs b/Program.cs index 2fdb49e..ecfc4a3 100644 --- a/Program.cs +++ b/Program.cs @@ -1,28 +1,21 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Management; -using System.Runtime.InteropServices; -using Benchmark; +#if DEBUG using BenchmarkDotNet.Configs; using BenchmarkDotNet.Running; -using Hardware.Info; -using NvAPIWrapper; -using NvAPIWrapper.Display; -using NvAPIWrapper.GPU; -using SharpDX.DXGI; -using Device = SharpDX.Direct3D11.Device; +#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)) { - DisplayMacInfo(); + MacOSHelper.DisplayMacInfo(); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) @@ -47,383 +40,74 @@ static void Main(string[] args) } } - static void DisplayMacInfo() - { - Console.ForegroundColor = ConsoleColor.Cyan; - var startInfo = new ProcessStartInfo - { - FileName = "/usr/sbin/system_profiler", - Arguments = "SPSoftwareDataType SPHardwareDataType SPMemoryDataType SPDisplaysDataType", - RedirectStandardOutput = true, - UseShellExecute = false - }; - - var process = new Process { StartInfo = startInfo }; - process.Start(); - - var exclusions = new List - { - "Serial Number (system):", "Hardware UUID:", "Model Number:", "Provisioning UDID:", "Boot Volume:", - "Boot Mode:", "Computer Name:", "User Name:", "Kernel Version: Darwin", "Secure Virtual Memory: Enabled", - "System Integrity Protection: Enabled", "Time since boot:", "System Firmware Version:", "OS Loader Version:", - "Activation Lock Status:", "Bus: Built-In", "Vendor:" - }; - - while (!process.StandardOutput.EndOfStream) - { - string? line = process.StandardOutput.ReadLine(); - if (line != null && !exclusions.Any(line.Contains)) - { - Console.WriteLine(line); - } - } - } - static void DisplayWindowsInfo() { ConsoleSpinner.Start(); - DisplayCpuInfo(); - DisplayRamInfo(); - DisplayGpuInfo(); + WindowsHelper.DisplayCpuInfo(); + WindowsHelper.DisplayRamInfo(); + DxGpuHelper.DisplayGpuInfo(); ConsoleSpinner.Stop(); } - static async void DisplayCpuInfo() - { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - using var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Processor"); - foreach (var item in searcher.Get()) - { - try - { - Console.ForegroundColor = ConsoleColor.Cyan; - Console.WriteLine("[CPU Information]"); - - Console.ForegroundColor = ConsoleColor.White; - Console.Write("Processor Name: "); - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine(item["Name"]); - - Console.ForegroundColor = ConsoleColor.White; - Console.Write("Cores: "); - Console.ForegroundColor = ConsoleColor.Yellow; - Console.Write($"{item["NumberOfCores"]}"); - - Console.ForegroundColor = ConsoleColor.White; - Console.Write(", Threads: "); - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine(item["NumberOfLogicalProcessors"]); - - Console.ForegroundColor = ConsoleColor.White; - Console.Write("Base Frequency: "); - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine("{0}MHz", item["MaxClockSpeed"]); - - IHardwareInfo hardwareInfo = new HardwareInfo(); - hardwareInfo.RefreshAll(); - Console.ForegroundColor = ConsoleColor.White; - Console.Write("Current Frequency: "); - Console.ForegroundColor = ConsoleColor.Yellow; - - foreach (var cpu in hardwareInfo.CpuList) - { - Console.WriteLine("{0}MHz", cpu.CurrentClockSpeed); - } - - Console.ForegroundColor = ConsoleColor.White; - Console.Write("L2 Cache: "); - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine("{0}MB", Convert.ToInt64(item["L2CacheSize"]) / 1024); - - Console.ForegroundColor = ConsoleColor.White; - Console.Write("L3 Cache: "); - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine("{0}MB", Convert.ToInt64(item["L3CacheSize"]) / 1024); - - Console.ForegroundColor = ConsoleColor.White; - Console.Write("Voltage: "); - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine("{0}V", item["CurrentVoltage"]); - - Console.ForegroundColor = ConsoleColor.Magenta; - Console.WriteLine("-----------------------------------------------------------"); - } - catch (Exception ex) - { - Console.WriteLine("An error occurred while retrieving CPU information: " + ex.Message); - } - await Task.Delay(500); - } - } - } - - static async void DisplayRamInfo() - { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - using var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMemory"); - try - { - long totalCapacity = 0; - string? manufacturer = null; - foreach (ManagementObject item in searcher.Get().Cast()) - { - totalCapacity += Convert.ToInt64(item["Capacity"]); - manufacturer = item["Manufacturer"]?.ToString()?.Trim(); - } - - Console.ForegroundColor = ConsoleColor.Cyan; - Console.WriteLine("[Memory Information]"); - - Console.ForegroundColor = ConsoleColor.White; - Console.Write("Total Capacity: "); - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine("{0} GB", totalCapacity / (1024 * 1024 * 1024)); - - Console.ForegroundColor = ConsoleColor.White; - Console.Write("Manufacturer: "); - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine(manufacturer); - - searcher.Query = new ObjectQuery("SELECT * FROM Win32_PhysicalMemory"); - int slotNumber = 1; - foreach (ManagementObject item in searcher.Get().Cast()) - { - Console.WriteLine(); - Console.ForegroundColor = ConsoleColor.White; - Console.WriteLine("(Slot {0})", slotNumber++); - - Console.Write("Speed: "); - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine("{0} MHz", item["Speed"]); - - Console.ForegroundColor = ConsoleColor.White; - Console.Write("Capacity: "); - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine("{0} GB", Convert.ToInt64(item["Capacity"]) / (1024 * 1024 * 1024)); - } - - Console.ForegroundColor = ConsoleColor.Magenta; - Console.WriteLine("-----------------------------------------------------------"); - } - catch (Exception ex) - { - Console.WriteLine("An error occurred while retrieving memory information: " + ex.Message); - } - await Task.Delay(500); - } - } - - static async void DisplayGpuInfo() - { - try - { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - using var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_VideoController"); - bool hasNvidiaGPU = PhysicalGPU.GetPhysicalGPUs().Any(gpu => gpu.FullName.Contains("NVIDIA")); - - if (hasNvidiaGPU) - { - NVIDIA.Initialize(); - var nvidiaGPUs = PhysicalGPU.GetPhysicalGPUs(); - var driver = NVIDIA.DriverVersion; - var driverbranch = NVIDIA.DriverBranchVersion; - - foreach (var gpu in nvidiaGPUs) - { - Console.ForegroundColor = ConsoleColor.Cyan; - Console.WriteLine("[GPU Information]"); - - Console.ForegroundColor = ConsoleColor.White; - Console.Write("GPU Type: "); - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine(gpu.GPUType); - - Console.ForegroundColor = ConsoleColor.White; - Console.Write("Name: "); - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine(gpu.FullName); - - Console.ForegroundColor = ConsoleColor.White; - Console.Write("GPU Core: "); - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine(gpu.ArchitectInformation.ShortName); - - Console.ForegroundColor = ConsoleColor.White; - Console.Write("Shaders: "); - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine(gpu.ArchitectInformation.NumberOfCores); - - var graphicsClockMHz = gpu.BoostClockFrequencies.GraphicsClock.Frequency / 1000; - Console.ForegroundColor = ConsoleColor.White; - Console.Write("GPU Core Speed: "); - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine("{0} MHz", graphicsClockMHz); - - Console.ForegroundColor = ConsoleColor.White; - Console.Write("VRAM: "); - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine("{0} MB", gpu.MemoryInformation.DedicatedVideoMemoryInkB / 1024); - - Console.ForegroundColor = ConsoleColor.White; - Console.Write("VRAM Type: "); - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine(gpu.MemoryInformation.RAMType); - - var memoryClockMHz = gpu.BoostClockFrequencies.MemoryClock.Frequency / 1000; - Console.ForegroundColor = ConsoleColor.White; - Console.Write("VRAM Frequency: "); - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine("{0} MHz", memoryClockMHz); - } - } - - foreach (var item in searcher.Get()) - { - var manufacturer = item["AdapterCompatibility"]?.ToString(); - if (manufacturer == null) continue; - - if (manufacturer.ToLower().Contains("nvidia")) continue; - - if (manufacturer.ToLower().Contains("intel") || manufacturer.ToLower().Contains("amd")) - { - Console.ForegroundColor = ConsoleColor.Magenta; - Console.WriteLine("-----------------------------------------------------------"); - - Console.ForegroundColor = ConsoleColor.Cyan; - Console.WriteLine("[Integrated GPU]"); - - Console.ForegroundColor = ConsoleColor.White; - Console.Write("Name: "); - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine(item["Name"]); - - Console.ForegroundColor = ConsoleColor.White; - Console.Write("Manufacturer: "); - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine(manufacturer); - - Console.ForegroundColor = ConsoleColor.White; - Console.Write("Driver Version: "); - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine(item["DriverVersion"]); - - Console.ForegroundColor = ConsoleColor.White; - Console.Write("VRAM: "); - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine("{0} MB", Convert.ToUInt64(item["AdapterRAM"]) / (1024 * 1024)); - - Console.ForegroundColor = ConsoleColor.Magenta; - Console.WriteLine("-----------------------------------------------------------"); - } - else - { - if (manufacturer.ToLower().Contains("advanced micro devices")) - { - manufacturer = "AMD"; - } - - if (!hasNvidiaGPU) - { - using var factory = new Factory1(); - using var adapter = factory.GetAdapter(0); - var desc = adapter.Description; - - Console.ForegroundColor = ConsoleColor.White; - Console.Write("Name: "); - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine(desc.Description); - - Console.ForegroundColor = ConsoleColor.White; - Console.Write("Manufacturer: "); - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine(manufacturer); - - Console.ForegroundColor = ConsoleColor.White; - Console.Write("Driver Version: "); - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine(item["DriverVersion"]); - - if (desc.DedicatedVideoMemory == 0) - { - Console.WriteLine("No dedicated GPU memory found"); - } - else - { - Console.ForegroundColor = ConsoleColor.White; - Console.Write("VRAM: "); - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine("{0} MB", desc.DedicatedVideoMemory / (1024 * 1024)); - - Console.ForegroundColor = ConsoleColor.White; - Console.Write("Shared Memory: "); - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine("{0} MB", desc.SharedSystemMemory / (1024 * 1024)); - } - - Console.ForegroundColor = ConsoleColor.Magenta; - Console.WriteLine("-----------------------------------------------------------"); - } - } - } - } - } - catch (Exception ex) - { - Console.WriteLine("An error occurred while retrieving GPU information: " + ex.Message); - } - await Task.Delay(500); - } - 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. Run all benchmarks"); + Console.WriteLine("5. Memory Bandwidth"); + Console.WriteLine("6. Run all benchmarks"); #if DEBUG - Console.WriteLine("6. Debug Mode"); + 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 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 { - ["1"] = () => HashBenchmark.CombinedHashing(), - ["2"] = () => EncrypBenchmark.RunEncryptBenchmark(), - ["3"] = () => CPUBenchmark.CpuPrimeCompute(), - ["4"] = () => MMUL.MultiplyMatrix(), - ["5"] = () => { HashBenchmark.CombinedHashing(); EncrypBenchmark.RunEncryptBenchmark(); CPUBenchmark.CpuPrimeCompute(); MMUL.MultiplyMatrix(); }, + ["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 - ["6"] = () => BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(new[] { "Benchmarks" }, new DebugInProcessConfig()) + ["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("-----------------------------------------------------------"); - Console.WriteLine(" "); - Stopwatch stopwatch = Stopwatch.StartNew(); // Start Global Timer + Stopwatch stopwatch = Stopwatch.StartNew(); benchmarkAction?.Invoke(); - stopwatch.Stop(); // Stop Global Timer + 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(); } diff --git a/README.md b/README.md index 3bed491..f596893 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,8 @@ - Install `.NET 9 SDK` from `here` - Install `.Net 9.0.0 Runtime` from `here` - Open the solution in your favourite IDE and set "Benchmark" as the startup project. -- Run the benchmark in `Release` mode. +- Run the project in `Release` mode and without debugging. +- For debugging see the `Debugging` section below. - Check your if system specs is correct - `Y` to continue - Select which benchmarks to run @@ -46,11 +47,14 @@ - Publish with `dotnet publish -c Release` - Run `Benchmark.exe` in the `C:\Users\\Benchmark\bin\Release\net9.0\publish\` folder. +# Download the EXE +- Download the latest release from `here` + + > [!NOTE] > This project is not signed or notarized (Can't afford apple developer lol) - -- On macOS you might need to allow the app to run in `System Preferences > Security & Privacy` then scroll down and click `Open Anyway`. -- On Windows you might need to allow the app to run in `Windows Security` then click `Run Anyway`. +> - On macOS you might need to allow the app to run in `System Preferences > Security & Privacy` then scroll down and click `Open Anyway`. +> - On Windows you might need to allow the app to run in `Windows Security` then click `Run Anyway`. # Required SDKs & Runtimes @@ -59,7 +63,8 @@ # Debugging - Set a breakpoint anywhere. -- Run the program in `Debug` mode. +- Run the program in `Debug` mode with debugger attached. +- Smaller datasets and iterations are used when debugger is attached. - Use option `6` to start debugging. - Select the benchmark you want to debug. - The program will pause at the breakpoint. @@ -81,12 +86,14 @@

MacOS Sequoia

- - + + - Scroll down to see results. +- Results are also exported to a `.txt` file located in the `bin\Release\net9.0\publish\` folder. +- If you are running the downloaded `.exe` file, the results will be in the same folder as the `.exe` file. - There might be up to a 20 seconds delay on first use due to hardware detection by `Hardware.Info`. # Output results @@ -97,8 +104,8 @@

MacOS Sequoia

- - + + diff --git a/ConsoleUtils.cs b/Utilities/ConsoleUtils.cs similarity index 77% rename from ConsoleUtils.cs rename to Utilities/ConsoleUtils.cs index b876cb6..ee3351a 100644 --- a/ConsoleUtils.cs +++ b/Utilities/ConsoleUtils.cs @@ -1,6 +1,3 @@ -using System; -using System.Threading; - class Spinner : IDisposable { private const string Sequence = @"/-\|"; @@ -58,6 +55,7 @@ public void Dispose() Stop(); } } + class ConsoleSpinner { private static readonly string[] SpinnerFrames = { "/", "-", "\\", "|" }; @@ -67,7 +65,10 @@ class ConsoleSpinner public static void Start() { - Console.CursorVisible = false; + if (!Console.IsOutputRedirected) + { + Console.CursorVisible = false; + } stopSpinner = false; spinnerThread = new Thread(Spin); spinnerThread.Start(); @@ -81,12 +82,18 @@ public static void Stop() private static void Spin() { - Console.CursorVisible = false; + if (!Console.IsOutputRedirected) + { + Console.CursorVisible = false; + } int frameIndex = 0; while (!stopSpinner) { Console.Write(SpinnerFrames[frameIndex]); - Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop); + if (!Console.IsOutputRedirected) + { + Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop); + } frameIndex = (frameIndex + 1) % SpinnerFrames.Length; Thread.Sleep(Interval); } @@ -114,30 +121,6 @@ public static void DisplayProgressBar(int progressPercentage) } } -class GcHelper -{ - public static void MemoryCleanUp() - { - Console.ForegroundColor = ConsoleColor.Green; - Console.WriteLine("-----------------------------------------------------------"); - - long memoryBefore = GC.GetTotalMemory(false); - - Console.ForegroundColor = ConsoleColor.Yellow; - Console.WriteLine("Cleaning up memory..."); - - GC.Collect(); - GC.WaitForPendingFinalizers(); - GC.Collect(); - - long memoryAfter = GC.GetTotalMemory(true); - long memoryFreed = memoryBefore - memoryAfter; - - Console.WriteLine($"Freed up {memoryFreed / (1024 * 1024 * 1024.0):F2} GB of memory."); - Console.WriteLine("-----------------------------------------------------------"); - } -} - class ConsoleIndeterminateBar { private const int ProgressBarWidth = 50; diff --git a/Utilities/ExportUtil.cs b/Utilities/ExportUtil.cs new file mode 100644 index 0000000..95cae24 --- /dev/null +++ b/Utilities/ExportUtil.cs @@ -0,0 +1,30 @@ +class BenchmarkExporter +{ + public string? BenchmarkVersion { get; set; } + public static void ExportResults(string filename, params string[] results) + { + string appDirectory = AppContext.BaseDirectory; + string filePath = Path.Combine(appDirectory, filename); + string totalTime = Program.TotalRunTime?.ToString() ?? "0"; + string version = ConsoleInfo.Version(); + string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + string output = $"Benchmark Run - {timestamp}\n" + $"Version: {version}\n" + + "--------------------------------\n" + + string.Join("\n", results) + "\n" + $"Total Run Time: {totalTime} ms\n" + + "\n--------------------------------\n"; + + File.AppendAllText(filePath, output); + Console.WriteLine($"Results exported to {filePath}"); + } + + public static void TestExportResults() + { + List testResults = new(); + testResults.Add("Hasing Benchmark: 1000ms."); + testResults.Add("Encryption Benchmark: 2000ms."); + testResults.Add("CPU Prime Computation: 3000ms."); + testResults.Add("CPU Matrix Multiplication: 4000ms."); + testResults.Add("Memory Bandwidth: 5000ms."); + ExportResults("TestResults.txt", testResults.ToArray()); + } +} \ No newline at end of file diff --git a/Utilities/MemoryUtil.cs b/Utilities/MemoryUtil.cs new file mode 100644 index 0000000..fe5fd41 --- /dev/null +++ b/Utilities/MemoryUtil.cs @@ -0,0 +1,23 @@ +class GcHelper +{ + public static void MemoryCleanUp() + { + Console.ForegroundColor = ConsoleColor.Green; + Console.WriteLine("-----------------------------------------------------------"); + + long memoryBefore = GC.GetTotalMemory(false); + + Console.ForegroundColor = ConsoleColor.Yellow; + Console.WriteLine("Cleaning up memory..."); + + GC.Collect(); + GC.WaitForPendingFinalizers(); + GC.Collect(); + + long memoryAfter = GC.GetTotalMemory(true); + long memoryFreed = memoryBefore - memoryAfter; + + Console.WriteLine($"Freed up {memoryFreed / (1024 * 1024 * 1024.0):F2} GB of memory."); + Console.WriteLine("-----------------------------------------------------------"); + } +} \ No newline at end of file