Skip to content

Instantly share code, notes, and snippets.

@voronoipotato
Created April 21, 2017 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save voronoipotato/3fca671b6010b113bf7cabb3ab4842e6 to your computer and use it in GitHub Desktop.
Save voronoipotato/3fca671b6010b113bf7cabb3ab4842e6 to your computer and use it in GitHub Desktop.
public class PaperTimer : IDisposable
{
private readonly Stopwatch _stopwatch;
private readonly Action<Stopwatch> _action;
public PaperTimer(Action<Stopwatch> action = null)
{
_action = action ?? (s => Console.WriteLine(s.ElapsedMilliseconds));
_stopwatch = new Stopwatch();
_stopwatch.Start();
}
public void Dispose()
{
_stopwatch.Stop();
_action(_stopwatch);
}
public Stopwatch Watch
{
get { return _stopwatch; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment