2020-12-27 22:52:14 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Flowframes.MiscUtils
|
|
|
|
|
|
{
|
|
|
|
|
|
class Benchmarker
|
|
|
|
|
|
{
|
2021-05-13 23:17:51 +02:00
|
|
|
|
// Benchmark a method with return type (via Delegate/Func)
|
|
|
|
|
|
public static object BenchmarkMethod(string methodName, Delegate method, params object[] args)
|
2020-12-27 22:52:14 +01:00
|
|
|
|
{
|
2021-05-13 23:17:51 +02:00
|
|
|
|
NmkdStopwatch sw = new NmkdStopwatch();
|
|
|
|
|
|
var returnVal = method.DynamicInvoke(args);
|
|
|
|
|
|
Logger.Log($"Ran {methodName} in {sw.GetElapsedStr()}", true);
|
|
|
|
|
|
return returnVal;
|
2020-12-27 22:52:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-13 23:17:51 +02:00
|
|
|
|
// Benchmark a void method (via Action)
|
|
|
|
|
|
public static void BenchmarkMethod(string methodName, Action method, params object[] args)
|
2020-12-27 22:52:14 +01:00
|
|
|
|
{
|
2021-05-13 23:17:51 +02:00
|
|
|
|
NmkdStopwatch sw = new NmkdStopwatch();
|
|
|
|
|
|
method.DynamicInvoke(args);
|
|
|
|
|
|
Logger.Log($"Ran {methodName} in {sw.GetElapsedStr()}", true);
|
2020-12-27 22:52:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|