我需要一個簡單的方法(如果可能,緊湊)在計算時間的同時執行一個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