Skip to content

Instantly share code, notes, and snippets.

@kasajian
Created May 20, 2014 02:31
Show Gist options
  • Save kasajian/095e0e6e5cd821c447da to your computer and use it in GitHub Desktop.
Save kasajian/095e0e6e5cd821c447da to your computer and use it in GitHub Desktop.
C Sharp Timer code for performance measuriment
// 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