Skip to content

Instantly share code, notes, and snippets.

@KevM
Created June 29, 2011 19:24
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 KevM/1054681 to your computer and use it in GitHub Desktop.
Save KevM/1054681 to your computer and use it in GitHub Desktop.
Stopwatch wrapper
private T with_timer<T>(Func<T> action)
{
Stopwatch sw = Stopwatch.StartNew();
var result = action();
sw.Stop();
TimeSpan time = sw.Elapsed;
System.Console.WriteLine("Time: {0:00}:{1:00}:{2:00}.{3:000}", time.Hours, time.Minutes, time.Seconds, time.Milliseconds);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment