48 lines
1.3 KiB
C#
48 lines
1.3 KiB
C#
|
// /**
|
|||
|
// * File: Timing.cs
|
|||
|
// * Author: haraldwolff
|
|||
|
// *
|
|||
|
// * This file and it's content is copyrighted by the Author and / or copyright holder.
|
|||
|
// * Any use wihtout proper permission is illegal and may lead to legal actions.
|
|||
|
// *
|
|||
|
// *
|
|||
|
// **/
|
|||
|
using System;
|
|||
|
using System.Diagnostics;
|
|||
|
using ln.logging;
|
|||
|
namespace ln.threading
|
|||
|
{
|
|||
|
public static class Timing
|
|||
|
{
|
|||
|
public delegate void VoidDelegate();
|
|||
|
public delegate T TypedDelegate<T>();
|
|||
|
|
|||
|
public static void Meassure(VoidDelegate f) => Meassure("", f);
|
|||
|
public static void Meassure(String prefix,VoidDelegate f)
|
|||
|
{
|
|||
|
Stopwatch stopwatch = new Stopwatch();
|
|||
|
stopwatch.Start();
|
|||
|
f();
|
|||
|
stopwatch.Stop();
|
|||
|
Logging.Log(LogLevel.DEBUG, "Timing({1}): {0}ms", stopwatch.ElapsedMilliseconds,prefix);
|
|||
|
}
|
|||
|
public static T Meassure<T>(TypedDelegate<T> f)
|
|||
|
{
|
|||
|
return Meassure("", f);
|
|||
|
}
|
|||
|
public static T Meassure<T>(String prefix,TypedDelegate<T> f)
|
|||
|
{
|
|||
|
Stopwatch stopwatch = new Stopwatch();
|
|||
|
stopwatch.Start();
|
|||
|
T r = f();
|
|||
|
stopwatch.Stop();
|
|||
|
Logging.Log(LogLevel.DEBUG, "Timing({1}): {0}ms", stopwatch.ElapsedMilliseconds,prefix);
|
|||
|
|
|||
|
return r;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
}
|