Dev Improvements #4

Merged
omegaleo merged 26 commits from dev into main 2025-12-09 23:55:56 +00:00
2 changed files with 115 additions and 38 deletions
Showing only changes of commit 1f893c30bb - Show all commits
+8 -1
View File
@@ -3,6 +3,7 @@
// /media/omegaleo/Development/Library Dev/HelperLib
using GameDevLibrary.Extensions;
using GameDevLibrary.Helpers;
using LibGit2Sharp;
using OmegaLeo.HelperLib.Git;
using OmegaLeo.HelperLib.Git.Models;
@@ -17,6 +18,8 @@ if (repo.IsNullOrEmpty())
var git = new GitClient(repo);
var result = BenchmarkUtility.Record(() =>
{
var changes = git.GetChanges();
if (changes.FolderName.IsNotNullOrEmpty())
@@ -42,7 +45,8 @@ if (changes.FolderName.IsNotNullOrEmpty())
msg = Console.ReadLine();
}
var signature = new Signature("Nuno 'Omega Leo' Diogo", "nunodiogo@omegaleo.pt", DateTimeOffset.Now);
var signature = new Signature("Nuno 'Omega Leo' Diogo", "nunodiogo@omegaleo.pt",
DateTimeOffset.Now);
git.Commit(msg, signature);
break;
@@ -62,6 +66,9 @@ else
{
Console.WriteLine("No changes found in specified repository");
}
});
Console.WriteLine($"Time for checking for changes: {result} ms");
Console.ReadLine();
@@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace GameDevLibrary.Helpers
{
public class BenchmarkUtility
{
private static Dictionary<string, List<long>> _benchmarks = new Dictionary<string, List<long>>();
private static Dictionary<string, Stopwatch> _stopwatches = new Dictionary<string, Stopwatch>();
private static Stopwatch GetStopwatch(string key)
{
Stopwatch stopwatch = new Stopwatch();
if (_stopwatches.TryGetValue(key, out stopwatch))
{
}
else
{
stopwatch = new Stopwatch();
_stopwatches.Add(key, stopwatch);
}
return stopwatch;
}
public static long Record(Action actionToRecord)
{
var stopwatch = new Stopwatch();
stopwatch.Start();
actionToRecord.Invoke();
stopwatch.Stop();
return stopwatch.ElapsedMilliseconds;
}
public static void Start(string key)
{
GetStopwatch(key).Restart();
}
public static void Stop(string key)
{
if (!_benchmarks.ContainsKey(key))
{
_benchmarks[key] = new List<long>();
}
GetStopwatch(key).Stop();
_benchmarks[key].Add(GetStopwatch(key).ElapsedMilliseconds);
}
public static List<long> GetResults(string key)
{
return _benchmarks.ContainsKey(key) ? _benchmarks[key] : new List<long>();
}
public static void ClearResults()
{
_benchmarks.Clear();
}
public static Dictionary<string, List<long>> GetAllResults()
{
return new Dictionary<string, List<long>>(_benchmarks);
}
}
}