2021-08-23 16:50:18 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Flowframes.MiscUtils
|
|
|
|
|
|
{
|
|
|
|
|
|
class Benchmarker
|
|
|
|
|
|
{
|
|
|
|
|
|
// Benchmark a method with return type (via Delegate/Func)
|
|
|
|
|
|
public static object BenchmarkMethod(string methodName, Delegate method, params object[] args)
|
|
|
|
|
|
{
|
|
|
|
|
|
NmkdStopwatch sw = new NmkdStopwatch();
|
|
|
|
|
|
var returnVal = method.DynamicInvoke(args);
|
2021-12-06 22:46:39 +01:00
|
|
|
|
Logger.Log($"Ran {methodName} in {sw}", true);
|
2021-08-23 16:50:18 +02:00
|
|
|
|
return returnVal;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Benchmark a void method (via Action)
|
|
|
|
|
|
public static void BenchmarkMethod(string methodName, Action method, params object[] args)
|
|
|
|
|
|
{
|
|
|
|
|
|
NmkdStopwatch sw = new NmkdStopwatch();
|
|
|
|
|
|
method.DynamicInvoke(args);
|
2021-12-06 22:46:39 +01:00
|
|
|
|
Logger.Log($"Ran {methodName} in {sw}", true);
|
2021-08-23 16:50:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|