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

Feature => Master #85

Merged
merged 35 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
cd1cf63
#80 - WIP: Memory bandwidth benchmark.
OudomMunint Feb 2, 2025
339f7d8
#79 - Fixed IO exception in vscode terminal due to output redirect.
OudomMunint Feb 2, 2025
3426b8f
Code clean up
OudomMunint Feb 2, 2025
b5eb022
Output formatting.
OudomMunint Feb 3, 2025
5308d2d
Fixed type, Formatting string to include hash data size.
OudomMunint Feb 3, 2025
4d666a7
#81 - Implement results export feature.
OudomMunint Feb 6, 2025
722f76b
#81 - Modified benchmarks to return results in string.
OudomMunint Feb 6, 2025
7fa4d30
#81 - Add results storage and export for benchmark tests, use new ret…
OudomMunint Feb 6, 2025
0d44e9c
Version +
OudomMunint Feb 6, 2025
562b62e
Update README to include download instructions and results export det…
OudomMunint Feb 6, 2025
607ca4a
Merge pull request #82 from OudomMunint/master
OudomMunint Feb 6, 2025
28d20a4
Add method to retrieve version for export.
OudomMunint Feb 6, 2025
21042c4
Add version information to benchmark results export #81
OudomMunint Feb 6, 2025
55534f2
Merge branch 'feature' of https://github.com/OudomMunint/Benchmark in…
OudomMunint Feb 6, 2025
1d1de1d
#83 - Moved images into /Media
OudomMunint Feb 7, 2025
99dd019
#83 - Addded Helper classes for gpu, macos, windows.
OudomMunint Feb 7, 2025
eae05dd
#83 - Added Export & Memory utilities.
OudomMunint Feb 7, 2025
a541c0e
#83 - Moved files into correct folders.
OudomMunint Feb 7, 2025
aff6f07
#81 - Pass in global runtime for export.
OudomMunint Feb 7, 2025
e76c9b3
#83 - Code clean up, removed redundant usings, moved some methods int…
OudomMunint Feb 7, 2025
de49f9a
#81 - Untract BenchmarkResults.txt
OudomMunint Feb 7, 2025
d4f180e
Fixed possible null ref on TotalTime var.
OudomMunint Feb 7, 2025
1b6cfc4
ReadMe - Corrected image paths and formatting notes
OudomMunint Feb 7, 2025
80a9e85
#83 - Remove unnecessary usings.
OudomMunint Feb 7, 2025
d43d089
#84 - Implement smaller datasets & iterations if Debugger.IsAttached …
OudomMunint Feb 8, 2025
9fe5a68
Implement test method for export results.
OudomMunint Feb 8, 2025
197bc03
Only load benchmark.net usings in debug mode, added more debugging op…
OudomMunint Feb 8, 2025
9adcc54
Documentation update.
OudomMunint Feb 8, 2025
9035b2a
#80 - Moved Memory benchmark out of debug.
OudomMunint Feb 8, 2025
8a64c6a
#80 - Majot refactor bandwidth test and an ST bandwidth test.
OudomMunint Feb 8, 2025
95b86bf
Fixed mem bandwidth test not included in add range
OudomMunint Feb 8, 2025
00c701e
Refactor Mem tests to return results.
OudomMunint Feb 8, 2025
6299782
testing new builds
OudomMunint Feb 8, 2025
3633704
#81 - Fixed results not being exported when running exe or dotnet pub…
OudomMunint Feb 8, 2025
52ee843
Dont allow builds on feature branch
OudomMunint Feb 8, 2025
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 @@ -77,6 +77,6 @@ jobs:
- name: Create Release
uses: ncipollo/[email protected]
with:
tag: v1.5.0
tag: v1.5.1
artifacts: "artifacts/**"
artifactContentType: application/octet-stream
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
*.userosscache
*.sln.docstates

# Generated results file
BenchmarkResults.txt

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

Expand Down
2 changes: 1 addition & 1 deletion Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<Version>1.5.0</Version>
<Version>1.5.1</Version>
<FileVersion>$([System.DateTime]::Now.ToString('yyyyMMddHH'))</FileVersion>
<Author>Dom</Author>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
162 changes: 142 additions & 20 deletions Benchmarks.cs → Benchmarks/Benchmarks.cs
Original file line number Diff line number Diff line change
@@ -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);
}
Expand All @@ -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();

Expand All @@ -41,24 +44,36 @@ 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;
private readonly Aes aes;

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();
Expand All @@ -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)
Expand All @@ -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...");

Expand All @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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];
Expand All @@ -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...");
Expand Down Expand Up @@ -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;
}
}
6 changes: 0 additions & 6 deletions OldBenchmark.cs → Benchmarks/OldBenchmark.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Loading
Loading