Reputation: 26333
what is best way to measure computation time, with either STL C++ or Qt?
I know of ctime, but I have an idea Qt could be of use here.
Thanks!
Upvotes: 2
Views: 1156
Reputation: 12317
Personally, I would use QElapsedTimer
:
http://doc.qt.io/qt-4.8/qelapsedtimer.html
Upvotes: 2
Reputation: 1
Theres the QTime class, that can measure time, you can start it via start()
and retrieve it via the elapsed()
method.
If you want something more advanced, you can go for Boost.Chrono if you want to get into serious time perversions. It gets real hairy real quick though, and the doc is a bit sparse (as always with Boost), but it's really one of the cleanest and best libraries if you need something of that caliber.
It all depends on what you want to do though, because "measuring time of computation" is a very broad description. Do you actually want to profile your application? Then maybe a profiler tool might be more suitable.
Also, if you just want to get the raw time it takes to execute the program, there's the time
command in Linux.
Upvotes: 5
Reputation: 4110
If you develop for Windows, you can use this from WINAPI:
DWORD start = ::GetTickCount();
calculation();
DWORD result = ::GetTickCount - start;
The DWORD result
will contain the passed time in milliseconds.
Note: That this way of measuring is not uber precise. The precision varies between 10 and 16 ms. But if you just want to display something like "It took 5.37 seconds to calculate the meaning of life" it will suffice.
Upvotes: 0