我正在测试一些类似方法调用的性能,这些方法调用包含在一些计时和日志记录语句中。我通过Action 委托参数传递这些方法。
有没有办法打印有关通话的详细信息?
例如:
var httpResult = TestService(() => serviceHttp.Search(criteria));
var tcpResult = TestService(() => serviceTcp.Search(criteria));
var localResult = TestService(() => servicelocal.Search(criteria));
...
private static double TestService(Action serviceOperation)
{
const int iterations = 15;
...
for (var i = 0; i < iterations; i++)
{
var watch = Stopwatch.StartNew();
...
Console.WriteLine(string.Format("{0} ElapsedMilliseconds={1}", ????, watch.ElapsedMilliseconds));
// Ideally this would print something like "serviceTcp.DoStuff(...) ElapsedMilliseconds=313"
}
...
}