Hello,
I have a problem in using time. I want to use and get microseconds on windows using C++.
I can't find the way.
Thnaks
Hello,
I have a problem in using time. I want to use and get microseconds on windows using C++.
I can't find the way.
Thnaks
Take a look at this: http://www.decompile.com/cpp/faq/windows_timer_api.htm
One popular way is using the QueryPerformanceCounter()
call. This is useful if you need high-precision timing, such as for measuring durations that only take on the order of microseconds. I believe this is implemented using the RDTSC
machine instruction.
There might be issues though, such as the counter frequency varying with power-saving, and synchronization between multiple cores. See the Wikipedia link above for details on these issues.
Take a look at the Windows APIs GetSystemTime()
/ GetLocalTime()
or GetSystemTimeAsFileTime()
.
GetSystemTimeAsFileTime() expresses time in 100 nanosecond intervals, that is 1/10 of a microsecond. All functions provide the current time with in millisecond accuracy.
EDIT:
Keep in mind, that on most Windows systems the system time is only updated about every 1 millisecond. So even representing your time with microsecond accuracy makes it still necessary to acquire the time with such a precision.
You can use boost date time library.
You can use boost::posix_time::hours, boost::posix_time::minutes, boost::posix_time::seconds, boost::posix_time::millisec, boost::posix_time::nanosec
http://www.boost.org/doc/libs/1%5F39%5F0/doc/html/date%5Ftime.html