diff --git a/VectoCore/VectoCore/Utils/ContextStopWatch.cs b/VectoCore/VectoCore/Utils/ContextStopWatch.cs new file mode 100644 index 0000000000000000000000000000000000000000..7814035b04daceb8901c04ab43e9a76e9a9dd453 --- /dev/null +++ b/VectoCore/VectoCore/Utils/ContextStopWatch.cs @@ -0,0 +1,29 @@ +using System; +using System.Diagnostics; + +namespace TUGraz.VectoCore.Utils +{ + /// <summary> + /// StopWatch which works like an IDisposable-Context. + /// Usage: using(new ContextStopWatch("main")) { ... } + /// </summary> + public class ContextStopWatch : Stopwatch, IDisposable + { + private readonly string _name; + + public ContextStopWatch(string name = null) + { + Start(); + _name = name; + } + + public void Dispose() + { + Stop(); + if (_name != null) + Console.WriteLine("{0}: {1}", _name, Elapsed); + else + Console.WriteLine(Elapsed); + } + } +} \ No newline at end of file