Dev changes (#5)
* Fixed dependency * Updates to NeoDictionary * Changes to NeoDictionary * Started working on a Git implementation to integrate into Game Engines in the future * Added commit functionality to the git library * New changes * Added select for NeoDictionary.cs * Fixed issue with previous new method * Added a Benchmarking Tool to be used mostly in game engines * Added IndexOf to NeoDictionary.cs * Added new method for BenchmarkUtility.cs * added an instacedobject class * Added a new shuffle method for lists * fixed return type * Added new Changelog generator * Added new Game logic library to assist with game projects * Added Web Project * Added Nuget package configs * Add workflow for publishing game library NuGet package * Add README for OmegaLeo's Helper Library * Updated Website to reflect all libraries * Fixed missing library in Changelog * Added Contributing and Code of Conduct * Fixed web project * new documentation changes * fix packages * Fixed DocumentationHelper package dependencies * Added Serilog * Added logging * Fixed documentation * Added logging for cache * fixed documentation * Updated README.md * Update README.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update OmegaLeo.HelperLib.Web/Controllers/HomeController.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update OmegaLeo.HelperLib.Web/Controllers/HomeController.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix error --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit was merged in pull request #5.
This commit is contained in:
@@ -1,14 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using NetFlow.DocumentationHelper.Library.Attributes;
|
||||
|
||||
namespace GameDevLibrary.Helpers
|
||||
{
|
||||
[Documentation(nameof(BenchmarkUtility), "Utility class for benchmarking code execution time.", null, @"```csharp
|
||||
BenchmarkUtility.Start(""MyBenchmark"");
|
||||
// Code to benchmark
|
||||
BenchmarkUtility.Stop(""MyBenchmark"");
|
||||
var results = BenchmarkUtility.GetResults(""MyBenchmark"");
|
||||
```")]
|
||||
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>();
|
||||
|
||||
[Documentation("GetStopwatch", "Retrieves or creates a Stopwatch instance for the given key.", null, null)]
|
||||
private static Stopwatch GetStopwatch(string key)
|
||||
{
|
||||
Stopwatch stopwatch;
|
||||
@@ -22,6 +30,14 @@ namespace GameDevLibrary.Helpers
|
||||
return stopwatch;
|
||||
}
|
||||
|
||||
[Documentation("Record", "Records the execution time of the provided action and returns the elapsed time in milliseconds.", null, @"```csharp
|
||||
var time = BenchmarkUtility.Record(() =>
|
||||
{
|
||||
// Code to benchmark
|
||||
});
|
||||
|
||||
Console.WriteLine($""Elapsed time: {time} ms"");
|
||||
```")]
|
||||
public static long Record(Action actionToRecord)
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
@@ -33,6 +49,19 @@ namespace GameDevLibrary.Helpers
|
||||
return stopwatch.ElapsedMilliseconds;
|
||||
}
|
||||
|
||||
[Documentation("RecordAndSaveToResults", "Records the execution time of the provided action, saves it under the given key, and returns the elapsed time in milliseconds.", null, @"```csharp
|
||||
var time = BenchmarkUtility.RecordAndSaveToResults(""MyBenchmark"", () =>
|
||||
{
|
||||
// Code to benchmark
|
||||
});
|
||||
|
||||
Console.WriteLine($""Elapsed time: {time} ms"");
|
||||
|
||||
var results = BenchmarkUtility.GetResults(""MyBenchmark"");
|
||||
|
||||
var averageTime = results.Average();
|
||||
Console.WriteLine($""Average time: {averageTime} ms"");
|
||||
```")]
|
||||
public static long RecordAndSaveToResults(string key, Action actionToRecord)
|
||||
{
|
||||
var stopwatch = new Stopwatch();
|
||||
@@ -52,11 +81,13 @@ namespace GameDevLibrary.Helpers
|
||||
return stopwatch.ElapsedMilliseconds;
|
||||
}
|
||||
|
||||
[Documentation("Start", "Starts or restarts the stopwatch for the given key.", null, null)]
|
||||
public static void Start(string key)
|
||||
{
|
||||
GetStopwatch(key).Restart();
|
||||
}
|
||||
|
||||
[Documentation("Stop", "Stops the stopwatch for the given key and records the elapsed time.", null, null)]
|
||||
public static void Stop(string key)
|
||||
{
|
||||
if (!_benchmarks.ContainsKey(key))
|
||||
@@ -68,16 +99,19 @@ namespace GameDevLibrary.Helpers
|
||||
_benchmarks[key].Add(GetStopwatch(key).ElapsedMilliseconds);
|
||||
}
|
||||
|
||||
[Documentation("GetResults", "Retrieves the list of recorded times for the given key.", null, null)]
|
||||
public static List<long> GetResults(string key)
|
||||
{
|
||||
return _benchmarks.ContainsKey(key) ? _benchmarks[key] : new List<long>();
|
||||
}
|
||||
|
||||
[Documentation("ClearResults", "Clears all recorded benchmark results.", null, null)]
|
||||
public static void ClearResults()
|
||||
{
|
||||
_benchmarks.Clear();
|
||||
}
|
||||
|
||||
[Documentation("GetAllResults", "Retrieves all recorded benchmark results.", null, null)]
|
||||
public static Dictionary<string, List<long>> GetAllResults()
|
||||
{
|
||||
return new Dictionary<string, List<long>>(_benchmarks);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NetFlow.DocumentationHelper.Library" Version="1.1.2" />
|
||||
<PackageReference Include="NetFlow.DocumentationHelper.Library" Version="1.1.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user