Skip to content

Instantly share code, notes, and snippets.

@leegould
Created April 26, 2012 15:49
Show Gist options
  • Save leegould/2500517 to your computer and use it in GitHub Desktop.
Save leegould/2500517 to your computer and use it in GitHub Desktop.
TimeThis
using System;
using System.Diagnostics;
namespace NewsfeedArchiverConsole
{
public class TimeThis : IDisposable
{
private readonly Stopwatch timer;
private readonly Action<string> func;
private readonly string endMessage;
public TimeThis(Action<string> writeFunc, string startMessage, string endMessage)
{
timer = new Stopwatch();
func = writeFunc;
this.endMessage = endMessage;
func(startMessage);
timer.Start();
}
#region IDisposable Members
public void Dispose()
{
func(endMessage + " : " + timer.Elapsed);
timer.Stop();
}
#endregion
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment