From 9acc18e1fa6473febcaf1a496e9b1f506d1cf2a7 Mon Sep 17 00:00:00 2001 From: "Nuno \"Omega Leo\" Diogo" Date: Mon, 13 Jan 2025 12:16:18 +0000 Subject: [PATCH] Added new method for BenchmarkUtility.cs --- .../Helpers/BenchmarkUtility.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/OmegaLeo.HelperLib/Helpers/BenchmarkUtility.cs b/OmegaLeo.HelperLib/Helpers/BenchmarkUtility.cs index be421b7..a6ec962 100644 --- a/OmegaLeo.HelperLib/Helpers/BenchmarkUtility.cs +++ b/OmegaLeo.HelperLib/Helpers/BenchmarkUtility.cs @@ -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(); + } + + _benchmarks[key].Add(stopwatch.ElapsedMilliseconds); + + return stopwatch.ElapsedMilliseconds; + } + public static void Start(string key) { GetStopwatch(key).Restart();