Skip to content

Instantly share code, notes, and snippets.

@nbxx
Created September 26, 2016 22:27
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 nbxx/13bd868ba70126b974b1239f73d98ad1 to your computer and use it in GitHub Desktop.
Save nbxx/13bd868ba70126b974b1239f73d98ad1 to your computer and use it in GitHub Desktop.
static void Main(string[] args)
{
RunStopwatch(() =>
{
foreach (var item in collection)
{
DoSomething(item);
}
});
}
public static void RunStopwatch(Action action)
{
// Run action, record timespan
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
action();
stopwatch.Stop();
Console.WriteLine(stopwatch.ElapsedMilliseconds);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment