Measuring time elapsed every loop iteration

Hey, I'm trying to measure the time elapsed in milliseconds since my game started running.

What I have is:

1
2
3
4
5
6
7
8
9
10
11
LONGLONG    level_start_time    =   0;
LONGLONG    level_elapsed_time  =   0; 

level_start_time = timeGetTime();
while(true) //game loop
{
   level_elapsed_time = timeGetTime() - level_start_time;
   // some more code here
   // some more code here
   // some more code here
}


Is this the proper way to do this? Thanks!
Checkout this link:
http://advancedcppwithexamples.blogspot.com/2009/08/measuring-elapsed-time-in-c-using_22.html

It has relevance to the frequency of calling the timeGetTime method with your use - it is called within your games main loop - depending on the logic of your game this may be called too frequently thus slowing things down due to system overhead.

If your games main loop (the while(true) loop) has some exit condition which breaks out of loop, then it may be wiser to put the level_elapsed_time statement after the while loop.

Topic archived. No new replies allowed.