Skip to content

Instantly share code, notes, and snippets.

@prabirshrestha
Created June 9, 2011 15:26
Show Gist options
  • Save prabirshrestha/1016973 to your computer and use it in GitHub Desktop.
Save prabirshrestha/1016973 to your computer and use it in GitHub Desktop.
Stopwatch helper
using System;
using System.Diagnostics;
public class StopWatchHelper : IDisposable
{
private readonly bool _displayTime;
private readonly Stopwatch _stopwatch;
public StopWatchHelper()
: this(true)
{
}
public StopWatchHelper(bool displayTime)
{
_displayTime = displayTime;
_stopwatch = new Stopwatch();
_stopwatch.Start();
}
public void Dispose()
{
_stopwatch.Stop();
if (_displayTime)
{
Console.WriteLine(_stopwatch.Elapsed);
}
}
public Stopwatch Stopwatch
{
get { return _stopwatch; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment