Hi
are there any windows equivalents to getimeofday() and timersub() ? i have tried GetLocalTime() but the "wSecond" is just in the range 0 to 59 ;-(
Any suggestions
Thanks in advanced.
Printable View
Hi
are there any windows equivalents to getimeofday() and timersub() ? i have tried GetLocalTime() but the "wSecond" is just in the range 0 to 59 ;-(
Any suggestions
Thanks in advanced.
what do you want ?Quote:
"wSecond" is just in the range 0 to 59 ;-(
i am calculating a transfer and simply just want to keep track of seconds. e.g obtain start time, then obtain time again after every recv() then do sub-second precision.
If i use GetLocalTime(), assuming i started at eg. 1:30:59, i could receive later at 1:31:00, and end up calculating the transfer took -59 seconds...
means you want to evaluate the 1:31:00 - 1:30:59 ?
why dont you just add 60 to the result. Here 60 + (-59) = 1sec.
put this in a if statement while wSecond is 0
Sounds like a perfect use for epoch time.
Check out http://www.epochconverter.com/progra...unctions-c.php
What about subsecond precision on windows? Are there any functions which can handle this? Like timersub() on unix?
The precision of a timer call is only about 15 milliseconds. So if you want to measure one single call you probably won't get any difference. You either need to use a high precision timer which is hardware dependent or measure a multiple of the same call, e. g. 100000 times. If doing the latter you normally call GetTickCount() rather then GetLocalTime, where the result already is in milliseconds.
Thank you for your replies.
I have also seen QueryPerformanceCounter(), is it possible to do sub second precision using this function ? If so can anyone suggest any information on using it.
Many thanks!
You might try to call the function passing a pointer to a LARGE_INTEGER variable.
If the returned value is 0 your hardware doesn't support a high performance counter.
If the call succeeds the 'li' would get a 64-bit integer which counts the closest ticks the performance counter would support, probably in nanoseconds.Code:static LARGE_INTEGER liempty = { 0 };
LARGE_INTEGER li = { 0 };
if (QueryPerformanceCounter(&li) == FALSE || li == liempty)
{
// no performance counter available
Ah yes, that's great, many thanks!