Created
May 20, 2014 02:31
-
-
Save kasajian/095e0e6e5cd821c447da to your computer and use it in GitHub Desktop.
C Sharp Timer code for performance measuriment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Stopwatch stopWatch = new Stopwatch(); | |
// using ( new Timer( stopWatch ) ) | |
// { | |
// Thread.Sleep(1000); | |
// } | |
// Print Timer.FormatTimeSpan(stopWatch.Elapsed); | |
// | |
public class Timer : IDisposable | |
{ | |
private Stopwatch stopWatch; | |
public Timer(Stopwatch stop) | |
{ | |
this.stopWatch = stop; | |
stopWatch.Start(); | |
} | |
public void Dispose() | |
{ | |
stopWatch.Stop(); | |
} | |
public static string FormatTimeSpan(TimeSpan ts) | |
{ | |
return String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment