PDA

View Full Version : Timing



Laz
02-04-2002, 08:42 AM
Is there a simple way to time things? i.e. - How can I make one thing happen for so many seconds, then do another thing for that many seconds?

marcus256
02-04-2002, 09:06 PM
Use a standard timer (such as glfwGetTime() - http://hem.passagen.se/opengl/glfw ), and do something like this:



double t1, t2;

// Do "stuff #1" for 3 seconds
t1 = glfwGetTime();
do
{
...
[stuff #1]
...
t2 = glfwGetTime();
}
while( (t2-t1) < 3.0 );

// Do "stuff #2" for 10 seconds
t1 = glfwGetTime();
do
{
...
[stuff #2]
...
t2 = glfwGetTime();
}
while( (t2-t1) < 10.0 );



[This message has been edited by marcus256 (edited 02-04-2002).]

bondi
02-04-2002, 10:29 PM
If you use Windows as operating system, you can use the Windows message WM_TIMER.
like this:

void Init()
{
...
//Id could be 1
//give time_intervall in ms
//if you give 3000 as time_intervall,
//Windows sends WM_TIMER every 3sec
SetTimer(ID,time_intervall);
...
}

Then, you can make your own Procedure for WM_TIMER.

If you want to quit your program, you must call this function "KillTimer(ID);"

Laz
02-05-2002, 06:22 AM
Okay thanks, i'll try each one and see what i like best :)

-Nick

Furrage
02-05-2002, 06:24 AM
Windows also has timeGetTime() and QueryPerformance*() which give much more accurate time and better resolution than WM_TIMER. For timeGetTime() each time you call it you get the current time in milliseconds. So call at the start and end of the section then subtract to get the time it took.

marcus256
02-06-2002, 06:02 AM
Windows also has timeGetTime() and QueryPerformance*() which give much more accurate time and better resolution than WM_TIMER.

glfwGetTime() uses Performance timer if it's available, or GetTickCount() if it's not (but the latter can really have worse resolution than 1 ms!).

However, he is probably asking for resolutions in the range of 0.1 second or so (see original post), so WM_TIMER should be ok.