I needed to also return value from a function and my approach was as follows:
public class PerformanceTests
{
private readonly stopwatch = new();
public (T Result, TimeSpan Elapsed) MeasureExecutionTime<T>(Func<T> function)
{
stopwatch.Restart();
var result = function();
stopwatch.Stop();
return (result, stopwatch.Elapsed);
}
}