Jump to content
  • Advertisement
Sign in to follow this  

QueryPerformanceCounter & Frametimes

This topic is 4355 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

There is something funny about my game. i used fraps to benchmark the average FPS of the game, plus the frametimes. my game sais that it runs with about 80 fps, thats just the same as fraps claims. but the frame time differs. one frame takes for about 12 ms, fraps sais it is done in about 6ms. why does this happen? it should be nearly the same value, but the frametimes are somehow doubled.
// just to let you know wich type the variables are:
double g_dElapsedTime;
float g_fFrameRate;
float g_fFrameTime;

LARGE_INTEGER g_startTime;
LARGE_INTEGER g_Frequency;

// Begin the scene

// End the scene
g_dTimeScale = 1.0 / g_i64Frequency.LowPart;

g_dElapsedTime = (g_i64EndTime.LowPart - g_i64StartTime.LowPart) * g_dTimeScale;
g_fFrameRate = 1.0f / (float)g_dElapsedTime;
g_fFrameTime = (float)g_dElapsedTime;

i thought it would work. since the frequency is 1 / s, i will get the time for each "beat" by reversing the frequency... multiplying with deltaTime should just return the frametime, but somehow it is doubled o.O *edit* i just calculated the frametime for 80 fps, it should be around 12,5 ms. is the benchmark for fraps bugged? *g

Share this post

Link to post
Share on other sites
A better way to get the frame time is to look at the delta between the same point in your code between frames. E.g., before you "begin the scene", grab the time and compute the difference between this and the last time you began the scene.

What you are timing is the time it takes to issue commands to the run-time, rather than the time taken to execute them. Although this would usually result in you getting artificially lower frame times (and higher fps).

Hmm... Also, what's up with the .LowParts? Just cast them to doubles, these values are 64bit for a reason. ;-)

Share this post

Link to post
Share on other sites
i am a bit confused about using 64 bit variables.
how should i proceed with calculating the frametimes?
LARGE_INTEGER contains a low and a high part, how should i convert this structure so i am able to fill a double with its value?
i have never worked with 64 bit integers before

Share this post

Link to post
Share on other sites
double d = (double)l.QuadPart; // Here's the conversion

This should give you a double with 2^32 + 1 in it. QuadPart is a LONGLONG, which is a typedef'ed __int64 which is a primitive type that can be cast to a double (don't you just love C++? ;-) ).

Using just the lowpart would give you all sorts of crazy timings, since this would overflow about 1 to 2 times per second.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!