// /** // * 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(); 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(TypedDelegate f) { return Meassure("", f); } public static T Meassure(String prefix,TypedDelegate 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; } } }