Skip to content

Commit

Permalink
Merge pull request #45 from OudomMunint/feature
Browse files Browse the repository at this point in the history
PR: Feature => Master
  • Loading branch information
OudomMunint authored Apr 12, 2024
2 parents a42ba13 + 99815d1 commit 2dc4f6a
Show file tree
Hide file tree
Showing 3 changed files with 219 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ jobs:
if: matrix.os == 'windows-latest'
uses: ncipollo/release-action@v1.14.0
with:
tag: v1.4.8.3
tag: v1.4.9
2 changes: 1 addition & 1 deletion Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
<PackageReference Include="Hardware.Info" Version="100.1.0" />
<PackageReference Include="NvAPIWrapper.Net" Version="0.8.1.101" />
<PackageReference Include="SharpDX" Version="4.2.0" />
<PackageReference Include="SharpDX.Direct3D11" Version="4.2.0" />
<PackageReference Include="System.Spec" Version="3.1.3" />
</ItemGroup>

</Project>
253 changes: 217 additions & 36 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,17 @@
using SharpDX.Direct3D;
using System;
using Device = SharpDX.Direct3D11.Device;
using NvAPIWrapper;
using NvAPIWrapper.Display;
using NvAPIWrapper.GPU;
using Hardware.Info;
using NvAPIWrapper.DRS.SettingValues;
using System.Linq;

Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Welcome to the best benchmark in the entire universe");

Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine("-----------------------------------------------------------");

if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
Expand Down Expand Up @@ -49,15 +58,45 @@
{
try
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("[CPU information]");
Console.WriteLine("Processor Name: {0}", item["Name"]);
Console.WriteLine("Manufacturer: {0}", item["Manufacturer"]);
Console.WriteLine("Core: {0}", item["NumberOfCores"]);
Console.WriteLine("Threads: {0}", item["NumberOfLogicalProcessors"]);
Console.WriteLine("Clock Speed: {0}MHz", item["MaxClockSpeed"]);
Console.WriteLine("L2 Cache: {0}MB", (Convert.ToInt64(item["L2CacheSize"]) / 1024));
Console.WriteLine("L3 Cache: {0}MB", (Convert.ToInt64(item["L3CacheSize"]) / 1024));
Console.WriteLine("Voltage: {0}V", item["CurrentVoltage"]);

Console.ForegroundColor = ConsoleColor.White;
Console.Write("Processor Name: ");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(item["Name"]);

Check warning on line 67 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

This call site is reachable on all platforms. 'ManagementBaseObject.this[string]' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Console.ForegroundColor = ConsoleColor.White;
Console.Write("Cores: ");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write($"{item["NumberOfCores"]}");

Check warning on line 72 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

This call site is reachable on all platforms. 'ManagementBaseObject.this[string]' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Console.ForegroundColor = ConsoleColor.White;
Console.Write(", Threads: ");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(item["NumberOfLogicalProcessors"]);

Console.ForegroundColor = ConsoleColor.White;
Console.Write("Clock Speed: ");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("{0}MHz", item["MaxClockSpeed"]);

Check warning on line 82 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

This call site is reachable on all platforms. 'ManagementBaseObject.this[string]' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 82 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

This call site is reachable on all platforms. 'ManagementBaseObject.this[string]' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Console.ForegroundColor = ConsoleColor.White;
Console.Write("L2 Cache: ");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("{0}MB", (Convert.ToInt64(item["L2CacheSize"]) / 1024));

Check warning on line 87 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

This call site is reachable on all platforms. 'ManagementBaseObject.this[string]' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 87 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

This call site is reachable on all platforms. 'ManagementBaseObject.this[string]' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

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)
Expand All @@ -82,46 +121,160 @@
manufacturer = item["Manufacturer"]?.ToString()?.Trim();

Check warning on line 121 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

This call site is reachable on all platforms. 'ManagementBaseObject.this[string]' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 121 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

This call site is reachable on all platforms. 'ManagementBaseObject.this[string]' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 121 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

This call site is reachable on all platforms. 'ManagementBaseObject.this[string]' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
}

Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("[Memory Information]");
Console.WriteLine("Total Capacity: {0} GB", totalCapacity / (1024 * 1024 * 1024));
Console.WriteLine("Manufacturer: {0}", manufacturer ?? "Unknown");

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);

// GET Capacity per stick
searcher.Query = new ObjectQuery("SELECT * FROM Win32_PhysicalMemory");

Check warning on line 138 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

This call site is reachable on all platforms. 'ObjectQuery' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 138 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

This call site is reachable on all platforms. 'ManagementObjectSearcher.Query' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 138 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

This call site is reachable on all platforms. 'ManagementObjectSearcher.Query' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
int slotNumber = 1;
foreach (ManagementObject item in searcher.Get())

Check warning on line 140 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

This call site is reachable on all platforms. 'ManagementObjectSearcher.Get()' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
{
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("(Slot {0})", slotNumber++);
Console.WriteLine("Speed: {0} MHz", item["Speed"]);
Console.WriteLine("Capacity: {0} GB", Convert.ToInt64(item["Capacity"]) / (1024 * 1024 * 1024));

Console.Write("Speed: " );
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("{0} MHz", item["Speed"]);

Check warning on line 148 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

This call site is reachable on all platforms. 'ManagementBaseObject.this[string]' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Console.ForegroundColor = ConsoleColor.White;
Console.Write("Capacity: ");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("{0} GB", Convert.ToInt64(item["Capacity"]) / (1024 * 1024 * 1024));

Check warning on line 153 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

This call site is reachable on all platforms. 'ManagementBaseObject.this[string]' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

}

Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine("-----------------------------------------------------------");
}
catch (Exception ex)
{
Console.WriteLine("An error occurred while retrieving memory information: " + ex.Message);
}
}

// Windows specific
// Retrieve GPU information
// iGPU + dGPU
// iGPU
try
{
using (var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_VideoController"))

Check warning on line 170 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

This call site is reachable on all platforms. 'ManagementObjectSearcher' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
{
bool hasNvidiaGPU = PhysicalGPU.GetPhysicalGPUs().Any(gpu => gpu.FullName.Contains("NVIDIA"));

if (hasNvidiaGPU)
{
NVIDIA.Initialize();

//var nvidiaGPUs = PhysicalGPU.GetPhysicalGPUs().Where(gpu => gpu.FullName.Contains("NVIDIA")).ToList();
var nvidiaGPUs = PhysicalGPU.GetPhysicalGPUs();
var driver = NVIDIA.DriverVersion;
var driverbranch = NVIDIA.DriverBranchVersion;

foreach (var gpu in nvidiaGPUs)
{
//Header
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 graphicsClockKHz = gpu.BoostClockFrequencies.GraphicsClock.Frequency;
var graphicsClockMHz = graphicsClockKHz / 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); // Convert kB to MB

Console.ForegroundColor = ConsoleColor.White;
Console.Write("VRAM Type: ");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(gpu.MemoryInformation.RAMType);

var memoryClockKHz = gpu.BoostClockFrequencies.MemoryClock.Frequency;
var memoryClockMHz = memoryClockKHz / 1000;

Console.ForegroundColor = ConsoleColor.White;
Console.Write("VRAM Frequency: ");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("{0} MHz", memoryClockMHz);

}
}

foreach (var item in searcher.Get())

Check warning on line 238 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

This call site is reachable on all platforms. 'ManagementObjectSearcher.Get()' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)
{
var manufacturer = item["AdapterCompatibility"]?.ToString();
var VideoMemoryType = item["VideoMemoryType"]?.ToString();

//if (manufacturer != null && manufacturer.ToLower().Contains("nvidia"))
//{
// hasNvidiaGPU = true;
// break; // Exit the loop if an NVIDIA GPU is found
//}

if (manufacturer != null && (manufacturer.ToLower().Contains("intel") || manufacturer.ToLower().Contains("amd")))
{
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine("-----------------------------------------------------------");

Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("[Integrated GPU]");
Console.WriteLine("Name: {0}", item["Name"]);
Console.WriteLine("Manufacturer: {0}", manufacturer);
Console.WriteLine("Driver Version: {0}", item["DriverVersion"]);
Console.WriteLine("VRAM: {0}MB", Convert.ToUInt64(item["AdapterRAM"]) / (1024 * 1024));

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"]);

Check warning on line 270 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

This call site is reachable on all platforms. 'ManagementBaseObject.this[string]' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

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
Expand All @@ -132,49 +285,77 @@
manufacturer = "AMD";
}

Console.WriteLine("[Dedicated GPU]");
Console.WriteLine("Number of GPUs: {0}", searcher.Get().Count);
Console.WriteLine("Name: {0}", item["Name"]);
Console.WriteLine("Manufacturer: {0}", manufacturer ?? "Unknown");
Console.WriteLine("Driver Version: {0}", item["DriverVersion"]);

using (var factory = new Factory1())
if (!hasNvidiaGPU)
{
using (var adapter = factory.GetAdapter(0))
using (var factory = new Factory1())
{
var desc = adapter.Description;

Console.WriteLine("Shared GPU Memory: {0}MB", desc.SharedSystemMemory / (1024 * 1024));
if (desc.DedicatedVideoMemory == 0)
using (var adapter = factory.GetAdapter(0))
{
Console.WriteLine("No dedicated GPU memory found");
}
else
{
Console.WriteLine("Dedicated GPU Memory: {0}MB", desc.DedicatedVideoMemory / (1024 * 1024));
var desc = adapter.Description;
var adapterMain = adapter;

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"]);

Check warning on line 310 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

This call site is reachable on all platforms. 'ManagementBaseObject.this[string]' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 310 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

This call site is reachable on all platforms. 'ManagementBaseObject.this[string]' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

Check warning on line 310 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

This call site is reachable on all platforms. 'ManagementBaseObject.this[string]' is only supported on: 'windows'. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

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("-----------------------------------------------------------");
}
Console.WriteLine("-----------------------------------------------------------");
}
}
}
}
}
}

catch (Exception ex)
{
Console.WriteLine("An error occurred while retrieving GPU information: " + ex.Message);
}

Console.ForegroundColor = ConsoleColor.White;
Console.Write("Continue to benchmark? (y/n): ");
var input = Console.ReadLine();

if (string.Equals(input, "y", StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine("Choose a benchmark to run:");

Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("1. Hashing Benchmark");
Console.WriteLine("2. Encryption Benchmark");
Console.WriteLine("3. Multithreading Benchmark");
Console.WriteLine("4. Run all benchmarks");

Console.ForegroundColor = ConsoleColor.White;
Console.Write("Enter the number of your choice: ");

string? choice = Console.ReadLine();
Expand Down

0 comments on commit 2dc4f6a

Please sign in to comment.