Skip to main content
gamedev.net
🔒 Locked

QueryPerformanceFrequency is wrong?

Started by billybob Dec 9, 2002 at 7:44 PM 5 replies 900+ views
Original Post
billybob
billybob
it seems that when i use QueryPerformanceFrequency to time one second its actually about 2 seconds. if i divide the result of QueryPerformanceFrequency by 1.975 it makes one second (timing the timer using timeGetTime()). is this a known thing or am i doing something wrong?
billybob
billybob
here it is without tweaking the frequency (it takes about 2 seconds to print a line)

1 seconds, 1000.002794 milliseconds, 1969 timeGetTime() ms
2 seconds, 1000.003352 milliseconds, 1969 timeGetTime() ms
3 seconds, 1000.003352 milliseconds, 1968 timeGetTime() ms
4 seconds, 1000.003352 milliseconds, 1969 timeGetTime() ms
5 seconds, 1000.002514 milliseconds, 1969 timeGetTime() ms
6 seconds, 1009.158147 milliseconds, 1969 timeGetTime() ms
7 seconds, 1000.003352 milliseconds, 2000 timeGetTime() ms
8 seconds, 1000.002514 milliseconds, 1969 timeGetTime() ms
9 seconds, 1000.003352 milliseconds, 1969 timeGetTime() ms
10 seconds, 1000.540571 milliseconds, 1984 timeGetTime() ms


here it is after dividing the frequency by 1.975:

1 seconds, 1000.004966 milliseconds, 1015 timeGetTime() ms
2 seconds, 1000.006069 milliseconds, 985 timeGetTime() ms
3 seconds, 1000.004966 milliseconds, 1000 timeGetTime() ms
4 seconds, 1000.233389 milliseconds, 984 timeGetTime() ms
5 seconds, 1000.003862 milliseconds, 1000 timeGetTime() ms
6 seconds, 1000.004966 milliseconds, 1016 timeGetTime() ms
7 seconds, 1000.006621 milliseconds, 1000 timeGetTime() ms
8 seconds, 1000.006069 milliseconds, 984 timeGetTime() ms
9 seconds, 1000.005517 milliseconds, 1000 timeGetTime() ms
10 seconds, 1000.005517 milliseconds, 1000 timeGetTime() ms
11 seconds, 1000.006621 milliseconds, 1000 timeGetTime() ms
12 seconds, 1000.004966 milliseconds, 1000 timeGetTime() ms
13 seconds, 1000.005517 milliseconds, 1000 timeGetTime() ms


edit: i should say, the first column is the number of timed seconds, the second column is how much time QueryPerformanceFrequency/QueryPerformanceCounter() thinks has passed, and the third column is how much time timeGetTime() thinks has passed. i'm pretty sure timeGetTime is right because it does take about 2 seconds to print a line in the first one, and one in the second one.

edit again: well, it actually appears to be some kind of type casting problem because when i tried to quiet the compiler about the loss of data warning with this line:

Frq.QuadPart /= 1.975;

by putting (__int64) before 1.975:

Frq.QuadPart /= (__int64)1.975;

it went back to two seconds! is there something wrong with the LARGE_INTEGER union?


[edited by - billybob on December 9, 2002 8:49:27 PM]

[edited by - billybob on December 9, 2002 8:51:50 PM]

[edited by - billybob on December 9, 2002 8:52:37 PM]
scaught
scaught
You''re doing integer division with a float. Your 1.975 is being converted to a 1.
alnite
alnite
Just to remind you:

quote:
From Visual Studio.NET Combined Help
The QueryPerformanceFrequency function retrieves the frequency of the high-resolution performance counter, if one exists. The frequency cannot change while the system is running.

BOOL QueryPerformanceFrequency(
LARGE_INTEGER *lpFrequency // current frequency
);

Parameters
lpFrequency
[out] Pointer to a variable that receives the current performance-counter frequency, in counts per second. If the installed hardware does not support a high-resolution performance counter, this parameter can be zero.


it is count per second, not miliseconds. You are not supposed to divide it by 1.975 or any number, unless a number from QueryPerformanceCounter.


My compiler generates one error message: "does not compile."

[edited by - alnite on December 9, 2002 9:04:53 PM]
billybob
billybob
ok, but so a strait up no garbage program would look like this:

LARGE_INTEGER Frq;
LARGE_INTEGER Stop;
LARGE_INTEGER Start;

QueryPerformanceFrequency(&Frq);
QueryPerformanceCounter(&Start);
QueryPerformanceCounter(&Stop);

the time between those two commands in seconds would be:

(Stop.QuadPart - Start.QuadPart) / Frq.QuadPart;

but that doesn''t work, it always comes out to about 2x what it should, or it waits twice as long.
alnite
alnite
strange, try to use INT64 instead of LARGE_INTEGER (casting from LARGE_INTEGER to INT64 is not a problem) and do the division. and as scaught said, 1.975 is converted to 1, just be aware of that.
I use QueryPerformance for my fps, and I got it correct, same with my monitor vertical refresh rate.


My compiler generates one error message: "does not compile."
billybob
billybob
well, the pos works on the old computer correctly, so i guess i''ll just have an option to use timeGetTime() because it doesn''t seem to work right. maybe new motherboard drivers or something.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.