Added new method for BenchmarkUtility.cs

This commit is contained in:
2025-01-13 12:16:18 +00:00
parent 7125bbc537
commit 9acc18e1fa
@@ -36,6 +36,25 @@ namespace GameDevLibrary.Helpers
return stopwatch.ElapsedMilliseconds;
}
public static long RecordAndSaveToResults(string key, Action actionToRecord)
{
var stopwatch = new Stopwatch();
stopwatch.Start();
actionToRecord.Invoke();
stopwatch.Stop();
if (!_benchmarks.ContainsKey(key))
{
_benchmarks[key] = new List<long>();
}
_benchmarks[key].Add(stopwatch.ElapsedMilliseconds);
return stopwatch.ElapsedMilliseconds;
}
public static void Start(string key)
{
GetStopwatch(key).Restart();