Skip to content

Instantly share code, notes, and snippets.

@bpringe
Created December 12, 2018 22:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bpringe/ce96b5a3e7b49058022753370468f61f to your computer and use it in GitHub Desktop.
Save bpringe/ce96b5a3e7b49058022753370468f61f to your computer and use it in GitHub Desktop.
Function to print time of operation and return result
public static T Time<T>(string op, Func<T> f)
{
var sw = Stopwatch.StartNew();
T result = f();
sw.Stop();
Console.WriteLine($"{op} took {sw.ElapsedMilliseconds} ms");
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment