Getting milliseconds of current time precision in Qt

The Qt documentation about QTime::currentTime()

says:

Note that accuracy depends on the accuracy of the operating system; not all systems provide 1 millisecond accuracy.

But is there a way to get this time with millisecond precision in Windows 7?

+3


source to share


3 answers


Timer resolution may vary on different platforms and readings may not be accurate. If you need to get an accurate high resolution timestamp on Windows 7, it provides the QPC API:

https://msdn.microsoft.com/en-us/library/windows/desktop/dn553408%28v=vs.85%29.aspx



GetSystemTimePreciseAsFileTime

is claimed to provide system time with <1us resolution.

But this is only an exact time stamp. If you need to do something with 1ms latency (for example, handle an event), you need an RTOS, not a desktop handle.

+2


source


One common way would be to magnify what you are doing and do it 10-100 times in a row, so you can get a more accurate time to read what you are doing by dividing the result by 10-100.



But getting millisecond accurate readings of your time is practically useless, because you don't have 100% of the processor time, which means that your readings will have much more variance than just 1 millisecond if the OS gives you a different process time while you are doing your actions. ...

0


source


you can use the functionality provided by the time.h header file in C / C ++.

#include <time.h> 
clock_t start, end; 
double cpu_time_used; 
int main()
{
    start = clock();
    /* Do the work. */ 
    end = clock(); 
    cpu_time_used = ((double)(end-start)/ CLOCKS_PER_SEC);
}

      

0


source







All Articles