我需要一个简单的方法(如果可能,紧凑)在计算时间的同时执行一个C#块。一些与此类似C++代码:如何轻松计时一段C#代码?
elapsed = time_call([&]
{
for_each (a.begin(), a.end(), [&](int n) {
results1.push_back(make_tuple(n, fibonacci(n)));
});
});
其中time_call是:
// Calls the provided work function and returns the number of milliseconds
// that it takes to call that function.
template <class Function>
__int64 time_call(Function&& f)
{
__int64 begin = GetTickCount();
f();
return GetTickCount() - begin;
}
我知道秒表方式...什么更紧凑?
这有什么错'Stopwatch'? – SLaks
秒表方式需要大约3行代码,你希望它有多紧凑? – harold