Darkleo’s Blog
Ein Schatz, der seinen Besitzer überallhin begleitet.

Zeitmessungen mit Monitoren

November 14th, 2007 by darkleo

public class Monitor : IDisposable
{
 System.Diagnostics.
Stopwatch sw;
 string prefix;
 public Monitor(string prefix)
 {
 this.prefix = prefix;
 sw = System.Diagnostics.
Stopwatch.StartNew();
 }
 public static Monitor Create(string prefix)
 {
return new Monitor(prefix); }

 public void Dispose()
 {
  Console.WriteLine(prefix + sw.ElapsedMilliseconds + " ms"); }
}

HowToUse:

using (Monitor monitor = Monitor.Create("Dauer: "))
{
 for (int i = 0; i < 100000; i++)
 {
//mach was
 }
}
//Dauer XXXXX ms

Posted in .NET, C#, Performance

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.