I am attempting to see how long several functions take to execute.
The code to do this is simply
public void GetTimeToProcess(string functionName)
{
// Create new stopwatch.
Stopwatch stopwatch = new Stopwatch();
// Begin timing.
stopwatch.Start();
// Do something.
for (int i = 0; i < 1000; i++)
{
Thread.Sleep(1);
}
// Stop timing.
stopwatch.Stop();
// Write result.
Console.WriteLine("Time elapsed ({1}): {0}", stopwatch.Elapsed,
functionName);
}
However, I do not want to pepper all my functions with new Stopwatch instances and the rest of this code. Rather somehow pass functions into this method or something else
What is the best way to get the execution time of several functions without copy and pasting this code into all of the functions?