Skip to content

Instantly share code, notes, and snippets.

@einarwh
Last active December 14, 2015 07:39
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 einarwh/5052307 to your computer and use it in GitHub Desktop.
Save einarwh/5052307 to your computer and use it in GitHub Desktop.
PerfTimer using using.
class Program
{
static void Main()
{
using (new PerfTimer())
{
// Do your thing.
}
}
}
class PerfTimer : IDisposable
{
private readonly Stopwatch _ = new Stopwatch();
public PerfTimer()
{
_.Start();
}
public void Dispose()
{
_.Stop();
Console.WriteLine("Spent {0} ms.", _.ElapsedMilliseconds);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment