Created
April 21, 2017 18:55
-
-
Save voronoipotato/3fca671b6010b113bf7cabb3ab4842e6 to your computer and use it in GitHub Desktop.
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
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