Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: feature => master #32

Merged
merged 7 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ jobs:
if: matrix.os == 'windows-latest'
uses: ncipollo/[email protected]
with:
tag: v1.4.7.1
tag: v1.4.8
193 changes: 106 additions & 87 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@

if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{

var startInfo = new ProcessStartInfo
{
FileName = "/usr/sbin/system_profiler",
Arguments = " sudo SPHardwareDataType SPDisplaysDataType",
Arguments = "SPHardwareDataType SPDisplaysDataType",
RedirectStandardOutput = true,
UseShellExecute = false
};
Expand All @@ -29,12 +28,14 @@

while (!process.StandardOutput.EndOfStream)
{
string line = process.StandardOutput.ReadLine();

Check warning on line 31 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

Converting null literal or possible null value to non-nullable type.

Check warning on line 31 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

Converting null literal or possible null value to non-nullable type.

Check warning on line 31 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

Converting null literal or possible null value to non-nullable type.
Console.WriteLine(line);
if (!line.Contains("Serial Number (system):") && !line.Contains("Hardware UUID:") && !line.Contains("Provisioning UDID:"))

Check warning on line 32 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

Dereference of a possibly null reference.

Check warning on line 32 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

Dereference of a possibly null reference.

Check warning on line 32 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

Dereference of a possibly null reference.
{
Console.WriteLine(line);
}
}

process.WaitForExit();

}

else
Expand All @@ -45,121 +46,139 @@
{
foreach (var item in searcher.Get())
{
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("L3 Cache: {0}MB", (Convert.ToInt64(item["L3CacheSize"]) / 1024));
Console.WriteLine("Voltage: {0}V", item["CurrentVoltage"]);
Console.WriteLine("-----------------------------------------------------------");
try
{
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.WriteLine("-----------------------------------------------------------");
}
catch (Exception ex)
{
Console.WriteLine("An error occurred while retrieving CPU information: " + ex.Message);
}
}
}

// GET RAM info
// Windows only
using (var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMemory"))
{
// GET total MEM
long totalCapacity = 0;
string manufacturer = null;
foreach (ManagementObject item in searcher.Get())
try
{
totalCapacity += Convert.ToInt64(item["Capacity"]);
manufacturer = item["Manufacturer"].ToString().Trim();
}
// GET total MEM
long totalCapacity = 0;
string manufacturer = null;

Check warning on line 77 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

Converting null literal or possible null value to non-nullable type.

Check warning on line 77 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

Converting null literal or possible null value to non-nullable type.

Check warning on line 77 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

Converting null literal or possible null value to non-nullable type.
foreach (ManagementObject item in searcher.Get())
{
totalCapacity += Convert.ToInt64(item["Capacity"]);
manufacturer = item["Manufacturer"].ToString().Trim();

Check warning on line 81 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

Dereference of a possibly null reference.

Check warning on line 81 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

Dereference of a possibly null reference.

Check warning on line 81 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

Dereference of a possibly null reference.
}

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

// GET Capacity per stick
searcher.Query = new ObjectQuery("SELECT * FROM Win32_PhysicalMemory");
int slotNumber = 1;
foreach (ManagementObject item in searcher.Get())
// GET Capacity per stick
searcher.Query = new ObjectQuery("SELECT * FROM Win32_PhysicalMemory");
int slotNumber = 1;
foreach (ManagementObject item in searcher.Get())

Check warning on line 91 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (macos-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.WriteLine("(Slot {0})", slotNumber++);
Console.WriteLine("Speed: {0} MHz", item["Speed"]);
Console.WriteLine("Capacity: {0} GB", Convert.ToInt64(item["Capacity"]) / (1024 * 1024 * 1024));
}
Console.WriteLine("-----------------------------------------------------------");
}
catch (Exception ex)
{
Console.WriteLine();
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.WriteLine("An error occurred while retrieving memory information: " + ex.Message);
}
Console.WriteLine("-----------------------------------------------------------");
}

// Windows specific
// Retrieve GPU information
// iGPU + dGPU
using (var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_VideoController"))
try
{
foreach (var item in searcher.Get())
using (var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_VideoController"))
{
var manufacturer = item["AdapterCompatibility"].ToString();
var VideoMemoryType = item["VideoMemoryType"].ToString();
if (manufacturer.ToLower().Contains("intel") || manufacturer.ToLower().Contains("amd"))
{
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.WriteLine("-----------------------------------------------------------");
}
else
foreach (var item in searcher.Get())

Check warning on line 113 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("[Dedicated GPU]");
Console.WriteLine("Name: {0}", item["Name"]);
Console.WriteLine("Manufacturer: {0}", manufacturer);
Console.WriteLine("Driver Version: {0}", item["DriverVersion"]);
var manufacturer = item["AdapterCompatibility"].ToString();

Check warning on line 115 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)
var VideoMemoryType = item["VideoMemoryType"].ToString();
if (manufacturer.ToLower().Contains("intel") || manufacturer.ToLower().Contains("amd"))

Check warning on line 117 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

Dereference of a possibly null reference.

Check warning on line 117 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

Dereference of a possibly null reference.

Check warning on line 117 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

Dereference of a possibly null reference.
{
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.WriteLine("-----------------------------------------------------------");
}
else
{
Console.WriteLine("[Dedicated GPU]");
Console.WriteLine("Number of GPUs: {0}", searcher.Get().Count);
Console.WriteLine("Name: {0}", item["Name"]);
Console.WriteLine("Manufacturer: {0}", manufacturer);
Console.WriteLine("Driver Version: {0}", item["DriverVersion"]);
}
}
}
}

using (var factory = new Factory1())
{
using (var adapter = factory.GetAdapter(0))
using (var factory = new Factory1())
{
var desc = adapter.Description;
Console.WriteLine("Total VRAM: {0}MB", desc.DedicatedVideoMemory / (1024 * 1024));
using (var adapter = factory.GetAdapter(0))
{
var desc = adapter.Description;
Console.WriteLine("Dedicated GPU Memory", desc.DedicatedVideoMemory / (1024 * 1024));
Console.WriteLine("Shared GPU Memory: {0}MB", desc.SharedSystemMemory / (1024 * 1024));
Console.WriteLine("-----------------------------------------------------------");
}
}
}
catch (Exception ex)
{
Console.WriteLine("An error occurred while retrieving GPU information: " + ex.Message);
}

Console.Write("Continue to benchmark? (y/n): ");
var input = Console.ReadLine();
if (string.Equals("y", "Y"))
{

Console.WriteLine("Choose a benchmark to run:");
Console.WriteLine("1. Hashing Benchmark");
Console.WriteLine("2. Encryption Benchmark");
Console.WriteLine("3. Multithreading Benchmark");
Console.WriteLine("4. Run all benchmarks");
Console.Write("Enter the number of your choice: ");

string choice = Console.ReadLine();

switch (choice)
{
case "1":
var hashingSummary = BenchmarkRunner.Run<HashingBenchmark>();
break;

case "2":
var encryptionSummary = BenchmarkRunner.Run<EncryptionBenchmark>();
break;
if (string.Equals(input, "y", StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine("Choose a benchmark to run:");
Console.WriteLine("1. Hashing Benchmark");
Console.WriteLine("2. Encryption Benchmark");
Console.WriteLine("3. Multithreading Benchmark");
Console.WriteLine("4. Run all benchmarks");
Console.Write("Enter the number of your choice: ");

case "3":
var multithreadingSummary = BenchmarkRunner.Run<MultithreadingBenchmark>();
break;
string choice = Console.ReadLine();

Check warning on line 165 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

Converting null literal or possible null value to non-nullable type.

Check warning on line 165 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

Converting null literal or possible null value to non-nullable type.

Check warning on line 165 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

Converting null literal or possible null value to non-nullable type.

case "4":
var runAll = BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).RunAllJoined();
break;
var benchmarkActions = new Dictionary<string, Action>
{
["1"] = () => BenchmarkRunner.Run<HashingBenchmark>(),
["2"] = () => BenchmarkRunner.Run<EncryptionBenchmark>(),
["3"] = () => BenchmarkRunner.Run<MultithreadingBenchmark>(),
["4"] = () => BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).RunAllJoined()
};

default:
Console.WriteLine("Invalid choice.");
break;
}
}
if (benchmarkActions.TryGetValue(choice, out Action benchmarkAction))

Check warning on line 175 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

Possible null reference argument for parameter 'key' in 'bool Dictionary<string, Action>.TryGetValue(string key, out Action value)'.

Check warning on line 175 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

Converting null literal or possible null value to non-nullable type.

Check warning on line 175 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

Possible null reference argument for parameter 'key' in 'bool Dictionary<string, Action>.TryGetValue(string key, out Action value)'.

Check warning on line 175 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

Converting null literal or possible null value to non-nullable type.

Check warning on line 175 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

Possible null reference argument for parameter 'key' in 'bool Dictionary<string, Action>.TryGetValue(string key, out Action value)'.

Check warning on line 175 in Program.cs

View workflow job for this annotation

GitHub Actions / Build (macos-latest)

Converting null literal or possible null value to non-nullable type.
{
benchmarkAction.Invoke();
}
else
{
Console.WriteLine("Invalid choice.");
}
}
}
Loading
Loading