|
-
November 27th, 2010, 12:38 PM
#1
Time functions on windows
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.
-
November 27th, 2010, 12:57 PM
#2
Re: Time functions on windows
"wSecond" is just in the range 0 to 59 ;-(
what do you want ?
-
November 27th, 2010, 01:06 PM
#3
Re: Time functions on windows
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...
-
November 27th, 2010, 01:16 PM
#4
Re: Time functions on windows
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
-
November 27th, 2010, 05:38 PM
#5
Re: Time functions on windows
-
November 29th, 2010, 08:14 AM
#6
Re: Time functions on windows
What about subsecond precision on windows? Are there any functions which can handle this? Like timersub() on unix?
-
November 29th, 2010, 11:25 AM
#7
Re: Time functions on windows
 Originally Posted by RipRage
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.
-
November 30th, 2010, 07:19 AM
#8
Re: Time functions on windows
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!
-
November 30th, 2010, 08:13 AM
#9
Re: Time functions on windows
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.
Code:
static LARGE_INTEGER liempty = { 0 };
LARGE_INTEGER li = { 0 };
if (QueryPerformanceCounter(&li) == FALSE || li == liempty)
{
// no performance counter available
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.
-
November 30th, 2010, 08:21 AM
#10
Re: Time functions on windows
Ah yes, that's great, many thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|