Dev changes (#3)
* 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
This commit was merged in pull request #3.
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
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 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();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user