Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to realise long-term high-resolution timing on windows using C++?

I need to get exact timestamps every couple of ms (20, 30, 40ms) over a long period of time (a couple of hours). The function in which the timestamp is taken is invoked as a callback by a 3rd-party library.

Using GetSystemTime() one can get the correct system timestamp but only with milliseconds accuracy, which is not precise enough for me. Using QueryPerformanceTimer() yields more accurate timestamps but is not synchronous to the system timestamp over a long period of time (see http://msdn.microsoft.com/en-us/magazine/cc163996.aspx).

The solution provided at the site linked above somehow works only on older computers, it hangs while synchronizing when i try to use it with newer computers.

It seems to me like boost is also only working on milliseconds accuracy. If possible, I'd like to avoid using external libraries, but if there's no other choice I'll go with it.

Any suggestions?

like image 441
fdlm Avatar asked Oct 09 '22 21:10

fdlm


1 Answers

Deleted article from CodeProject, this seems to be the copy: DateTimePrecise C# Class The idea is to use QueryPerformanceCounter API for accurate small increments and periodically adjust it in order to keep long term accuracy. This is about to give microsecond accuracy ("about" because it's still not exactly precise, but still quite usable).

See also: Microsecond resolution timestamps on Windows

like image 196
Roman R. Avatar answered Oct 13 '22 11:10

Roman R.