Jump to content
  • Advertisement
Sign in to follow this  
Kija

QueryPerformanceCounter, 40ms resolution?

This topic is 4829 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

Heya, I'm using this code for QueryPerformanceCounter:
FLOAT GetTime()
{
	static BOOL created = FALSE;
	static LONGLONG ticksPerSec = 0;
	static LARGE_INTEGER time;
	static FLOAT finalTime;

	if (created == FALSE)
	{
		LARGE_INTEGER temp;
		QueryPerformanceFrequency(&temp);
		ticksPerSec = temp.QuadPart;

		created = TRUE;
	}

	QueryPerformanceCounter(&time);

	finalTime = (FLOAT)(time.QuadPart / (DOUBLE)ticksPerSec);
	return finalTime;
}

I call this every frame in my little game project. I have about ~400 fps and I call this function and I log it, every frame. This is a snappet of the result:
302 fps.GetTime(): 537626.125000
303 fps.GetTime(): 537626.125000
304 fps.GetTime(): 537626.125000
305 fps.GetTime(): 537626.125000
306 fps.GetTime(): 537626.125000
307 fps.GetTime(): 537626.125000
308 fps.GetTime(): 537626.125000
309 fps.GetTime(): 537626.125000
310 fps.GetTime(): 537626.187500
311 fps.GetTime(): 537626.187500
312 fps.GetTime(): 537626.187500
313 fps.GetTime(): 537626.187500
314 fps.GetTime(): 537626.187500
315 fps.GetTime(): 537626.187500
316 fps.GetTime(): 537626.187500
317 fps.GetTime(): 537626.187500
318 fps.GetTime(): 537626.187500
319 fps.GetTime(): 537626.187500
320 fps.GetTime(): 537626.187500
321 fps.GetTime(): 537626.187500
322 fps.GetTime(): 537626.187500
323 fps.GetTime(): 537626.187500
324 fps.GetTime(): 537626.187500
325 fps.GetTime(): 537626.187500
326 fps.GetTime(): 537626.187500
327 fps.GetTime(): 537626.187500
328 fps.GetTime(): 537626.250000
329 fps.GetTime(): 537626.250000
330 fps.GetTime(): 537626.250000
331 fps.GetTime(): 537626.250000

So 17 times in a row, it gives the same value. So during my 400 frames under a second, it changes the time about 400 / 17 = 24 times and 1 / 24 = 0,042 That is a resolution of 42 ms... What am I missing? O.o

Share this post


Link to post
Share on other sites
Advertisement
It's probably floating point precision that's truncating your results. Try printing out the actual value stored in time.QuadPart and I bet it changes every time.

Enigma

Share this post


Link to post
Share on other sites
Yep, you're right Enigma. I log every time in the GetTime() function now and .QuadPart does change everytime, and the frequency (ticksPerSec) is unchanged. I've changed all variables to be DOUBLE instead of FLOAT but it's still not working. Even when I print it to the logfile it shows the same truncated results (even after I've changed to DOUBLE). So it didn't change anything :/

However, the reason seems to be that the values are too big, especially QuadPart. So I made it a bit smaller before the division and then it works. This is however, not as elegant, and it is static and I have to change the value all the time. I believe that the timer gives how many nanoseconds it is since the system was started, maybe it's my uptime for about a week that makes the numbers huge?

So here's the relevant part of the code:

a = (DOUBLE)absTime.QuadPart - 2040000000000;
b = (DOUBLE)ticksPerSec;
c = a / b;
time = (DOUBLE)((DOUBLE)absTime.QuadPart / (DOUBLE)ticksPerSec);
logger->Log("%f / %f = %f <//> %f", (DOUBLE)absTime.QuadPart, (DOUBLE)ticksPerSec, (DOUBLE)time, c);



And here is the output:

2040624077712.000000 / 3579545.000000 = 570079.187500 <//> 174.345535
2040624095287.000000 / 3579545.000000 = 570079.187500 <//> 174.350449
2040624095448.000000 / 3579545.000000 = 570079.187500 <//> 174.350494
2040624095559.000000 / 3579545.000000 = 570079.187500 <//> 174.350525
2040624105588.000000 / 3579545.000000 = 570079.187500 <//> 174.353333
2040624105678.000000 / 3579545.000000 = 570079.187500 <//> 174.353348
2040624105727.000000 / 3579545.000000 = 570079.187500 <//> 174.353363
2040624116048.000000 / 3579545.000000 = 570079.187500 <//> 174.356247
2040624116128.000000 / 3579545.000000 = 570079.187500 <//> 174.356262
2040624116177.000000 / 3579545.000000 = 570079.187500 <//> 174.356277
2040624126559.000000 / 3579545.000000 = 570079.187500 <//> 174.359177
2040624126635.000000 / 3579545.000000 = 570079.187500 <//> 174.359222
2040624126684.000000 / 3579545.000000 = 570079.187500 <//> 174.359222
2040624137680.000000 / 3579545.000000 = 570079.187500 <//> 174.362289
2040624137796.000000 / 3579545.000000 = 570079.187500 <//> 174.362320
2040624137843.000000 / 3579545.000000 = 570079.187500 <//> 174.362350
2040624147532.000000 / 3579545.000000 = 570079.187500 <//> 174.365036
2040624147634.000000 / 3579545.000000 = 570079.187500 <//> 174.365082
2040624147683.000000 / 3579545.000000 = 570079.187500 <//> 174.365097
2040624157993.000000 / 3579545.000000 = 570079.187500 <//> 174.367981
2040624158083.000000 / 3579545.000000 = 570079.187500 <//> 174.367996
2040624158131.000000 / 3579545.000000 = 570079.187500 <//> 174.368011
2040624168486.000000 / 3579545.000000 = 570079.187500 <//> 174.370911
2040624168564.000000 / 3579545.000000 = 570079.187500 <//> 174.370926
2040624168611.000000 / 3579545.000000 = 570079.187500 <//> 174.370941
2040624185948.000000 / 3579545.000000 = 570079.187500 <//> 174.375778
2040624186032.000000 / 3579545.000000 = 570079.187500 <//> 174.375809
2040624186081.000000 / 3579545.000000 = 570079.187500 <//> 174.375824
2040624196440.000000 / 3579545.000000 = 570079.187500 <//> 174.378708
2040624196524.000000 / 3579545.000000 = 570079.187500 <//> 174.378738
2040624196570.000000 / 3579545.000000 = 570079.187500 <//> 174.378738
2040624206916.000000 / 3579545.000000 = 570079.187500 <//> 174.381638
2040624206990.000000 / 3579545.000000 = 570079.187500 <//> 174.381653
2040624207039.000000 / 3579545.000000 = 570079.187500 <//> 174.381668
2040624217654.000000 / 3579545.000000 = 570079.250000 <//> 174.384644
2040624217739.000000 / 3579545.000000 = 570079.250000 <//> 174.384659
2040624217786.000000 / 3579545.000000 = 570079.250000 <//> 174.384674
2040624228052.000000 / 3579545.000000 = 570079.250000 <//> 174.387543
2040624228147.000000 / 3579545.000000 = 570079.250000 <//> 174.387573
2040624228194.000000 / 3579545.000000 = 570079.250000 <//> 174.387589
2040624238398.000000 / 3579545.000000 = 570079.250000 <//> 174.390427
2040624238485.000000 / 3579545.000000 = 570079.250000 <//> 174.390457
2040624238534.000000 / 3579545.000000 = 570079.250000 <//> 174.390472
2040624248868.000000 / 3579545.000000 = 570079.250000 <//> 174.393372
2040624248949.000000 / 3579545.000000 = 570079.250000 <//> 174.393387
2040624248995.000000 / 3579545.000000 = 570079.250000 <//> 174.393402
2040624259355.000000 / 3579545.000000 = 570079.250000 <//> 174.396286
2040624259437.000000 / 3579545.000000 = 570079.250000 <//> 174.396317
2040624259483.000000 / 3579545.000000 = 570079.250000 <//> 174.396317
2040624270082.000000 / 3579545.000000 = 570079.250000 <//> 174.399277
2040624270165.000000 / 3579545.000000 = 570079.250000 <//> 174.399307
2040624270211.000000 / 3579545.000000 = 570079.250000 <//> 174.399323
2040624280583.000000 / 3579545.000000 = 570079.250000 <//> 174.402222
2040624280697.000000 / 3579545.000000 = 570079.250000 <//> 174.402252
2040624280811.000000 / 3579545.000000 = 570079.250000 <//> 174.402283
2040624290835.000000 / 3579545.000000 = 570079.250000 <//> 174.405075
2040624290919.000000 / 3579545.000000 = 570079.250000 <//> 174.405106
2040624290966.000000 / 3579545.000000 = 570079.250000 <//> 174.405106
2040624308315.000000 / 3579545.000000 = 570079.250000 <//> 174.409958
2040624308416.000000 / 3579545.000000 = 570079.250000 <//> 174.409988
2040624308498.000000 / 3579545.000000 = 570079.250000 <//> 174.410004
2040624319051.000000 / 3579545.000000 = 570079.250000 <//> 174.412964
2040624319150.000000 / 3579545.000000 = 570079.250000 <//> 174.412994
2040624319197.000000 / 3579545.000000 = 570079.250000 <//> 174.412994
2040624329432.000000 / 3579545.000000 = 570079.250000 <//> 174.415863
2040624329539.000000 / 3579545.000000 = 570079.250000 <//> 174.415894
2040624329586.000000 / 3579545.000000 = 570079.250000 <//> 174.415909
2040624339780.000000 / 3579545.000000 = 570079.250000 <//> 174.418747
2040624339875.000000 / 3579545.000000 = 570079.250000 <//> 174.418793
2040624339924.000000 / 3579545.000000 = 570079.250000 <//> 174.418793
2040624350251.000000 / 3579545.000000 = 570079.250000 <//> 174.421692
2040624350334.000000 / 3579545.000000 = 570079.250000 <//> 174.421707
2040624350380.000000 / 3579545.000000 = 570079.250000 <//> 174.421722
2040624360762.000000 / 3579545.000000 = 570079.250000 <//> 174.424622
2040624360868.000000 / 3579545.000000 = 570079.250000 <//> 174.424652
2040624360917.000000 / 3579545.000000 = 570079.250000 <//> 174.424652
2040624371483.000000 / 3579545.000000 = 570079.250000 <//> 174.427597
2040624371577.000000 / 3579545.000000 = 570079.250000 <//> 174.427643
2040624371624.000000 / 3579545.000000 = 570079.250000 <//> 174.427658
2040624381714.000000 / 3579545.000000 = 570079.250000 <//> 174.430466
2040624381810.000000 / 3579545.000000 = 570079.250000 <//> 174.430496
2040624381857.000000 / 3579545.000000 = 570079.250000 <//> 174.430511
2040624392196.000000 / 3579545.000000 = 570079.250000 <//> 174.433395
2040624392278.000000 / 3579545.000000 = 570079.250000 <//> 174.433411
2040624392324.000000 / 3579545.000000 = 570079.250000 <//> 174.433426
2040624402679.000000 / 3579545.000000 = 570079.250000 <//> 174.436325
2040624402759.000000 / 3579545.000000 = 570079.250000 <//> 174.436340
2040624402807.000000 / 3579545.000000 = 570079.250000 <//> 174.436371
2040624413165.000000 / 3579545.000000 = 570079.250000 <//> 174.439255
2040624413245.000000 / 3579545.000000 = 570079.250000 <//> 174.439285
2040624413291.000000 / 3579545.000000 = 570079.250000 <//> 174.439301
2040624423697.000000 / 3579545.000000 = 570079.250000 <//> 174.442200
2040624423814.000000 / 3579545.000000 = 570079.250000 <//> 174.442230
2040624423861.000000 / 3579545.000000 = 570079.250000 <//> 174.442245
2040624434152.000000 / 3579545.000000 = 570079.250000 <//> 174.445129
2040624434256.000000 / 3579545.000000 = 570079.250000 <//> 174.445145
2040624434303.000000 / 3579545.000000 = 570079.250000 <//> 174.445160



So the third part is a normal division of the two first ones and it doesn't change often at all. But the fourth part is the same divison except that I take away 2040000000000 from it before the division. And then I get a sufficient resolution.

Any ideas on what I'm missing or how I could fix it to hold these large numbers? I've tried long double but the result seems to be the same.

Share this post


Link to post
Share on other sites
Don't try to measure absolute time stamps with the performance counter, they're pretty much meaningless in themselves anyway. Calculate the time elapsed between two samples (with a full 64-bit integer subtraction) and convert the result to a float instead.
Another method is to calculate time values relative to the application's startup in much the same way, however you may get run into problems with this approach if you let the application run for too long (due to integer wrapping).

Share this post


Link to post
Share on other sites
By default, "%f" and similar format strings will only output 6 significant digits, the rest is truncated. You can increase this with the following syntax: "%.16f", which will print up to 16 decimals.

So your values are really correct, it's the printing that is limited. Doubles are generally fine when using QueryPerformanceCounter, but it's better to keep the full 64-bit integer format, using __int64. As doynax suggests, after you calculate the elapsed time it's safe and convenient to convert it to float.

Share this post


Link to post
Share on other sites
Quote:
Original post by aaron_ds
function calls take time. try using inline, or putting it in a loop

Function calls generally take 1 to 10 clock cycles. So you'll need a timer with a resolution of around a nanoseconds to even detect it. Only the Time Stamp Counter is capable of this, in fact it counts clock cycles. Anyway, the conclusion is that one call takes a negligible amount of time. Only when calling a function millions of times per second it becomes noticable so one might consider to inline it or use other low-level optimizations.

Share this post


Link to post
Share on other sites
For what I know (and tested) QueryPerformanceCounter has a resolution << 40 ms!!! (it's < 1ms)
The overhead is about 20 micro seconds (0.02 ms) so it's negligible.
You have done something wrong...what are those numbers you show? seconds? or are they already milliseconds ???
Now I've not the code here...if you cannot resolve the problem I will post the block of your interest.

Share this post


Link to post
Share on other sites
I don't want to just get the time difference, I need the full time. And the function call is not the problem.

I use this function to get the full time, and also to take the difference in the time, but it's not enough that it just gives the diff. And I use the difference in time to multiply my player movement. So if I get a difference of 0.1 second I move my character 0.1 * units_per_sec.

I realised that the performance was wrong because my character moved 0.00000 units most frames, and every now and then it jumped pretty far say 0.5 for example. So, the difference is 0 and then the character move 0 units. I have this problem with the code, but my friend doesn't. The thing that differs is that I have a AMD64 2.2GHz and he has a P4 2.8 GHz. On his computer, the code works close to flawlessly. I'll post our common code and his and mine outputs from it.

Code:

static BOOL counterCreated = FALSE;
static LONGLONG ticksPerSec = 0;
static LARGE_INTEGER absTime;
static DOUBLE time, cappedQuadPart;

if (counterCreated == FALSE)
{
LARGE_INTEGER qwTicksPerSec;
QueryPerformanceFrequency(&qwTicksPerSec);
ticksPerSec = qwTicksPerSec.QuadPart;

counterCreated = TRUE;
}

QueryPerformanceCounter(&absTime);
time = (absTime.QuadPart / (DOUBLE)ticksPerSec);

file << absTime.QuadPart << " / " << ticksPerSec << " = " << setprecision(15) << time << endl;




AMD64 results:

2132979000477 / 3579545 = 595879.9375
2132979013789 / 3579545 = 595879.9375
2132979013885 / 3579545 = 595879.9375
2132979013912 / 3579545 = 595879.9375
2132979027008 / 3579545 = 595879.9375
2132979027065 / 3579545 = 595879.9375
2132979027116 / 3579545 = 595879.9375
2132979040173 / 3579545 = 595879.9375
2132979040230 / 3579545 = 595879.9375
2132979040256 / 3579545 = 595879.9375
2132979053055 / 3579545 = 595879.9375
2132979053105 / 3579545 = 595879.9375
2132979053137 / 3579545 = 595879.9375
2132979066009 / 3579545 = 595879.9375
2132979066088 / 3579545 = 595879.9375
2132979066115 / 3579545 = 595879.9375
2132979080662 / 3579545 = 595879.9375
2132979080748 / 3579545 = 595879.9375
2132979080774 / 3579545 = 595879.9375
2132979094223 / 3579545 = 595879.9375
2132979094311 / 3579545 = 595879.9375
2132979094337 / 3579545 = 595879.9375
2132979134285 / 3579545 = 595879.9375
2132979134425 / 3579545 = 595879.9375
2132979134452 / 3579545 = 595879.9375
2132979147536 / 3579545 = 595879.9375
2132979147667 / 3579545 = 595879.9375
2132979147697 / 3579545 = 595879.9375
2132979160847 / 3579545 = 595879.9375
2132979160903 / 3579545 = 595879.9375
2132979160930 / 3579545 = 595879.9375
2132979176379 / 3579545 = 595880
2132979176491 / 3579545 = 595880
2132979176516 / 3579545 = 595880
2132979189719 / 3579545 = 595880
2132979189780 / 3579545 = 595880
2132979189806 / 3579545 = 595880
2132979202857 / 3579545 = 595880
2132979202936 / 3579545 = 595880
2132979202962 / 3579545 = 595880
2132979215939 / 3579545 = 595880
2132979216017 / 3579545 = 595880
2132979216043 / 3579545 = 595880
2132979229126 / 3579545 = 595880
2132979229180 / 3579545 = 595880
2132979229230 / 3579545 = 595880
2132979242148 / 3579545 = 595880
2132979242202 / 3579545 = 595880
2132979242228 / 3579545 = 595880
2132979256138 / 3579545 = 595880
2132979256216 / 3579545 = 595880
2132979256265 / 3579545 = 595880
2132979270630 / 3579545 = 595880
2132979270703 / 3579545 = 595880
2132979270729 / 3579545 = 595880
2132979284905 / 3579545 = 595880
2132979284977 / 3579545 = 595880
2132979285026 / 3579545 = 595880
2132979299780 / 3579545 = 595880
2132979299859 / 3579545 = 595880
2132979299909 / 3579545 = 595880
2132979313144 / 3579545 = 595880
2132979313244 / 3579545 = 595880
2132979313270 / 3579545 = 595880
2132979326230 / 3579545 = 595880
2132979326410 / 3579545 = 595880
2132979326436 / 3579545 = 595880
2132979366006 / 3579545 = 595880
2132979366115 / 3579545 = 595880
2132979366142 / 3579545 = 595880
2132979379170 / 3579545 = 595880
2132979379223 / 3579545 = 595880
2132979379248 / 3579545 = 595880
2132979392514 / 3579545 = 595880.0625
2132979392605 / 3579545 = 595880.0625
2132979392633 / 3579545 = 595880.0625
2132979407167 / 3579545 = 595880.0625
2132979407273 / 3579545 = 595880.0625
2132979407300 / 3579545 = 595880.0625
2132979420192 / 3579545 = 595880.0625
2132979420270 / 3579545 = 595880.0625
2132979420296 / 3579545 = 595880.0625
2132979433285 / 3579545 = 595880.0625
2132979433362 / 3579545 = 595880.0625
2132979433390 / 3579545 = 595880.0625
2132979446246 / 3579545 = 595880.0625
2132979446297 / 3579545 = 595880.0625
2132979446324 / 3579545 = 595880.0625
2132979459646 / 3579545 = 595880.0625
2132979459709 / 3579545 = 595880.0625
2132979459735 / 3579545 = 595880.0625
2132979472627 / 3579545 = 595880.0625
2132979472680 / 3579545 = 595880.0625
2132979472708 / 3579545 = 595880.0625
2132979487516 / 3579545 = 595880.0625
2132979487622 / 3579545 = 595880.0625
2132979487649 / 3579545 = 595880.0625
2132979500758 / 3579545 = 595880.0625
2132979500839 / 3579545 = 595880.0625
2132979500866 / 3579545 = 595880.0625
2132979514121 / 3579545 = 595880.0625
2132979514181 / 3579545 = 595880.0625
2132979514207 / 3579545 = 595880.0625
2132979528001 / 3579545 = 595880.0625
2132979528096 / 3579545 = 595880.0625
2132979528124 / 3579545 = 595880.0625
2132979541331 / 3579545 = 595880.0625
2132979541391 / 3579545 = 595880.0625
2132979541418 / 3579545 = 595880.0625
2132979554461 / 3579545 = 595880.0625
2132979554542 / 3579545 = 595880.0625
2132979554569 / 3579545 = 595880.0625
2132979567400 / 3579545 = 595880.0625
2132979567500 / 3579545 = 595880.0625
2132979567550 / 3579545 = 595880.0625
2132979582701 / 3579545 = 595880.0625
2132979582821 / 3579545 = 595880.0625
2132979582854 / 3579545 = 595880.0625
2132979596351 / 3579545 = 595880.0625
2132979596444 / 3579545 = 595880.0625
2132979596471 / 3579545 = 595880.0625
2132979609218 / 3579545 = 595880.0625
2132979609304 / 3579545 = 595880.0625
2132979609335 / 3579545 = 595880.0625
2132979624231 / 3579545 = 595880.125
2132979624341 / 3579545 = 595880.125
2132979624367 / 3579545 = 595880.125
2132979637825 / 3579545 = 595880.125
2132979637913 / 3579545 = 595880.125
2132979637939 / 3579545 = 595880.125
2132979651540 / 3579545 = 595880.125
2132979651605 / 3579545 = 595880.125
2132979651631 / 3579545 = 595880.125
2132979665157 / 3579545 = 595880.125
2132979665246 / 3579545 = 595880.125
2132979665273 / 3579545 = 595880.125
2132979678552 / 3579545 = 595880.125
2132979678609 / 3579545 = 595880.125
2132979678660 / 3579545 = 595880.125
2132979692022 / 3579545 = 595880.125
2132979692108 / 3579545 = 595880.125
2132979692136 / 3579545 = 595880.125
2132979706832 / 3579545 = 595880.125
2132979706918 / 3579545 = 595880.125
2132979706953 / 3579545 = 595880.125
2132979720327 / 3579545 = 595880.125
2132979720412 / 3579545 = 595880.125
2132979720439 / 3579545 = 595880.125
2132979733850 / 3579545 = 595880.125
2132979733911 / 3579545 = 595880.125
2132979733960 / 3579545 = 595880.125
2132979747981 / 3579545 = 595880.125
2132979748084 / 3579545 = 595880.125
2132979748111 / 3579545 = 595880.125




P4 results:

87266150110062 / 2856540000 = 30549.59765625
87266150202674 / 2856540000 = 30549.59765625
87266150241614 / 2856540000 = 30549.59765625
87266160241806 / 2856540000 = 30549.6015625
87266160331574 / 2856540000 = 30549.6015625
87266160369514 / 2856540000 = 30549.6015625
87266169952058 / 2856540000 = 30549.60546875
87266170040322 / 2856540000 = 30549.60546875
87266170078122 / 2856540000 = 30549.60546875
87266179752930 / 2856540000 = 30549.609375
87266179841826 / 2856540000 = 30549.609375
87266179880122 / 2856540000 = 30549.609375
87266189674218 / 2856540000 = 30549.61328125
87266189774174 / 2856540000 = 30549.61328125
87266189812394 / 2856540000 = 30549.61328125
87266200480198 / 2856540000 = 30549.615234375
87266200570862 / 2856540000 = 30549.615234375
87266200609754 / 2856540000 = 30549.615234375
87266210290250 / 2856540000 = 30549.619140625
87266210381890 / 2856540000 = 30549.619140625
87266210420254 / 2856540000 = 30549.619140625
87266219447942 / 2856540000 = 30549.623046875
87266219538238 / 2856540000 = 30549.623046875
87266219577190 / 2856540000 = 30549.623046875
87266229491966 / 2856540000 = 30549.626953125
87266229580570 / 2856540000 = 30549.626953125
87266229618646 / 2856540000 = 30549.626953125
87266239498862 / 2856540000 = 30549.62890625
87266239591930 / 2856540000 = 30549.62890625
87266239629934 / 2856540000 = 30549.62890625
87266250171074 / 2856540000 = 30549.6328125
87266250261282 / 2856540000 = 30549.6328125
87266250299674 / 2856540000 = 30549.6328125
87266259325414 / 2856540000 = 30549.63671875
87266259418170 / 2856540000 = 30549.63671875
87266259456246 / 2856540000 = 30549.63671875
87266268593194 / 2856540000 = 30549.640625
87266268683494 / 2856540000 = 30549.640625
87266268721378 / 2856540000 = 30549.640625
87266278235066 / 2856540000 = 30549.642578125
87266278322266 / 2856540000 = 30549.642578125
87266278360686 / 2856540000 = 30549.642578125
87266288014662 / 2856540000 = 30549.646484375
87266288103594 / 2856540000 = 30549.646484375
87266288142078 / 2856540000 = 30549.646484375
87266297630970 / 2856540000 = 30549.650390625
87266297721762 / 2856540000 = 30549.650390625
87266297760202 / 2856540000 = 30549.650390625
87266308875234 / 2856540000 = 30549.654296875
87266308967822 / 2856540000 = 30549.654296875
87266309007834 / 2856540000 = 30549.654296875
87266318059702 / 2856540000 = 30549.658203125
87266318146918 / 2856540000 = 30549.658203125
87266318185306 / 2856540000 = 30549.658203125
87266327344070 / 2856540000 = 30549.66015625
87266327435274 / 2856540000 = 30549.66015625
87266327473402 / 2856540000 = 30549.66015625
87266337089114 / 2856540000 = 30549.6640625
87266337179098 / 2856540000 = 30549.6640625
87266337219470 / 2856540000 = 30549.6640625
87266346827846 / 2856540000 = 30549.66796875
87266346918238 / 2856540000 = 30549.66796875
87266346957090 / 2856540000 = 30549.66796875
87266356613574 / 2856540000 = 30549.669921875
87266356704494 / 2856540000 = 30549.669921875
87266356743018 / 2856540000 = 30549.669921875
87266366387330 / 2856540000 = 30549.673828125
87266366482226 / 2856540000 = 30549.673828125
87266366520770 / 2856540000 = 30549.673828125
87266376125486 / 2856540000 = 30549.677734375
87266376216322 / 2856540000 = 30549.677734375
87266376254486 / 2856540000 = 30549.677734375
87266385873410 / 2856540000 = 30549.681640625
87266385962938 / 2856540000 = 30549.681640625
87266386001410 / 2856540000 = 30549.681640625
87266396627898 / 2856540000 = 30549.685546875
87266396719770 / 2856540000 = 30549.685546875
87266396757646 / 2856540000 = 30549.685546875
87266406271070 / 2856540000 = 30549.6875
87266406359086 / 2856540000 = 30549.6875
87266406399554 / 2856540000 = 30549.6875
87266415984282 / 2856540000 = 30549.69140625
87266416073566 / 2856540000 = 30549.69140625
87266416112058 / 2856540000 = 30549.69140625
87266425989402 / 2856540000 = 30549.6953125
87266426079018 / 2856540000 = 30549.6953125
87266426117442 / 2856540000 = 30549.6953125
87266435730374 / 2856540000 = 30549.69921875
87266435820946 / 2856540000 = 30549.69921875
87266435858906 / 2856540000 = 30549.69921875
87266445324406 / 2856540000 = 30549.701171875
87266445412698 / 2856540000 = 30549.701171875
87266445451142 / 2856540000 = 30549.701171875
87266455489106 / 2856540000 = 30549.705078125
87266455578670 / 2856540000 = 30549.705078125
87266455617462 / 2856540000 = 30549.705078125
87266465681270 / 2856540000 = 30549.708984375
87266465769218 / 2856540000 = 30549.708984375
87266465808610 / 2856540000 = 30549.708984375
87266475467190 / 2856540000 = 30549.712890625
87266475555702 / 2856540000 = 30549.712890625
87266475593822 / 2856540000 = 30549.712890625
87266485508258 / 2856540000 = 30549.716796875
87266485599422 / 2856540000 = 30549.716796875
87266485637542 / 2856540000 = 30549.716796875
87266496160094 / 2856540000 = 30549.71875
87266496248698 / 2856540000 = 30549.71875
87266496286526 / 2856540000 = 30549.71875
87266505964374 / 2856540000 = 30549.72265625
87266506059054 / 2856540000 = 30549.72265625
87266506098678 / 2856540000 = 30549.72265625
87266515719546 / 2856540000 = 30549.7265625
87266515808422 / 2856540000 = 30549.7265625
87266515846610 / 2856540000 = 30549.7265625
87266525479586 / 2856540000 = 30549.73046875
87266525566950 / 2856540000 = 30549.73046875
87266525605562 / 2856540000 = 30549.73046875
87266535846778 / 2856540000 = 30549.734375
87266535936254 / 2856540000 = 30549.734375
87266535973850 / 2856540000 = 30549.734375
87266545431330 / 2856540000 = 30549.736328125
87266545520078 / 2856540000 = 30549.736328125
87266545558766 / 2856540000 = 30549.736328125
87266555274838 / 2856540000 = 30549.740234375
87266555366254 / 2856540000 = 30549.740234375
87266555405022 / 2856540000 = 30549.740234375
87266565596266 / 2856540000 = 30549.744140625
87266565686674 / 2856540000 = 30549.744140625
87266565725790 / 2856540000 = 30549.744140625
87266574748042 / 2856540000 = 30549.748046875
87266574838190 / 2856540000 = 30549.748046875
87266574876726 / 2856540000 = 30549.748046875
87266584024354 / 2856540000 = 30549.75
87266584113094 / 2856540000 = 30549.75
87266584151422 / 2856540000 = 30549.75
87266592906842 / 2856540000 = 30549.75390625
87266592995966 / 2856540000 = 30549.75390625
87266593064546 / 2856540000 = 30549.75390625
87266603032250 / 2856540000 = 30549.7578125
87266603143446 / 2856540000 = 30549.7578125
87266603182314 / 2856540000 = 30549.7578125
87266612200658 / 2856540000 = 30549.759765625
87266612292250 / 2856540000 = 30549.759765625
87266612330450 / 2856540000 = 30549.759765625
87266622874926 / 2856540000 = 30549.763671875
87266622962074 / 2856540000 = 30549.763671875
87266622999918 / 2856540000 = 30549.763671875
87266632566638 / 2856540000 = 30549.767578125
87266632657230 / 2856540000 = 30549.767578125
87266632696034 / 2856540000 = 30549.767578125
87266642299222 / 2856540000 = 30549.771484375
87266642388890 / 2856540000 = 30549.771484375
87266642427338 / 2856540000 = 30549.771484375
87266651888522 / 2856540000 = 30549.7734375
87266651980058 / 2856540000 = 30549.7734375
87266652018558 / 2856540000 = 30549.7734375
87266661853474 / 2856540000 = 30549.77734375
87266661944038 / 2856540000 = 30549.77734375
87266661982534 / 2856540000 = 30549.77734375
87266671492114 / 2856540000 = 30549.78125
87266671581378 / 2856540000 = 30549.78125
87266671619606 / 2856540000 = 30549.78125
87266681280142 / 2856540000 = 30549.78515625
87266681369970 / 2856540000 = 30549.78515625
87266681408634 / 2856540000 = 30549.78515625
87266697987006 / 2856540000 = 30549.791015625
87266698077930 / 2856540000 = 30549.791015625
87266698116410 / 2856540000 = 30549.791015625
87266707599886 / 2856540000 = 30549.79296875
87266707688094 / 2856540000 = 30549.79296875
87266707726770 / 2856540000 = 30549.79296875
87266717348798 / 2856540000 = 30549.796875
87266717437382 / 2856540000 = 30549.796875
87266717476130 / 2856540000 = 30549.796875
87266726934370 / 2856540000 = 30549.80078125
87266727023534 / 2856540000 = 30549.80078125
87266727063022 / 2856540000 = 30549.80078125
87266736633398 / 2856540000 = 30549.8046875
87266736719714 / 2856540000 = 30549.8046875
87266736758570 / 2856540000 = 30549.8046875
87266748252854 / 2856540000 = 30549.80859375
87266748343482 / 2856540000 = 30549.80859375
87266748383106 / 2856540000 = 30549.80859375
87266757864446 / 2856540000 = 30549.810546875
87266757958390 / 2856540000 = 30549.810546875
87266757997070 / 2856540000 = 30549.810546875
87266767057834 / 2856540000 = 30549.814453125
87266767146742 / 2856540000 = 30549.814453125
87266767185522 / 2856540000 = 30549.814453125
87266777636914 / 2856540000 = 30549.818359375
87266777725034 / 2856540000 = 30549.818359375
87266777763610 / 2856540000 = 30549.818359375
87266787397970 / 2856540000 = 30549.822265625
87266787488638 / 2856540000 = 30549.822265625
87266787527534 / 2856540000 = 30549.822265625
87266797003330 / 2856540000 = 30549.82421875
87266797094766 / 2856540000 = 30549.82421875
87266797132530 / 2856540000 = 30549.82421875
87266806769666 / 2856540000 = 30549.828125
87266806881330 / 2856540000 = 30549.828125
87266806919474 / 2856540000 = 30549.828125
87266817410946 / 2856540000 = 30549.83203125
87266817502042 / 2856540000 = 30549.83203125
87266817540462 / 2856540000 = 30549.83203125
87266828231282 / 2856540000 = 30549.8359375
87266828321902 / 2856540000 = 30549.8359375
87266828361518 / 2856540000 = 30549.8359375
87266838016206 / 2856540000 = 30549.83984375
87266838108266 / 2856540000 = 30549.83984375
87266838146674 / 2856540000 = 30549.83984375
87266847635678 / 2856540000 = 30549.841796875
87266847725886 / 2856540000 = 30549.841796875
87266847764626 / 2856540000 = 30549.841796875
87266857067934 / 2856540000 = 30549.845703125
87266857156914 / 2856540000 = 30549.845703125
87266857196002 / 2856540000 = 30549.845703125
87266866692438 / 2856540000 = 30549.849609375
87266866782762 / 2856540000 = 30549.849609375
87266866821682 / 2856540000 = 30549.849609375
87266876368170 / 2856540000 = 30549.853515625
87266876455858 / 2856540000 = 30549.853515625
87266876493974 / 2856540000 = 30549.853515625
87266887006478 / 2856540000 = 30549.857421875
87266887094658 / 2856540000 = 30549.857421875
87266887132690 / 2856540000 = 30549.857421875
87266896818110 / 2856540000 = 30549.859375
87266896933562 / 2856540000 = 30549.859375
87266896972734 / 2856540000 = 30549.859375
87266906022854 / 2856540000 = 30549.86328125
87266906113094 / 2856540000 = 30549.86328125
87266906151438 / 2856540000 = 30549.86328125
87266915775242 / 2856540000 = 30549.8671875
87266915867370 / 2856540000 = 30549.8671875
87266915906146 / 2856540000 = 30549.8671875
87266925816506 / 2856540000 = 30549.869140625
87266925911998 / 2856540000 = 30549.869140625
87266925951174 / 2856540000 = 30549.869140625
87266934980818 / 2856540000 = 30549.873046875
87266935069546 / 2856540000 = 30549.873046875
87266935107522 / 2856540000 = 30549.873046875
87266945636926 / 2856540000 = 30549.876953125
87266945725642 / 2856540000 = 30549.876953125
87266945764714 / 2856540000 = 30549.876953125
87266960281362 / 2856540000 = 30549.8828125
87266960376042 / 2856540000 = 30549.8828125
87266960414374 / 2856540000 = 30549.8828125
87266973657762 / 2856540000 = 30549.88671875
87266973748122 / 2856540000 = 30549.88671875
87266973786858 / 2856540000 = 30549.88671875




As you see my AMD64 gives the same value for about 20-30 frames, and the P4 changes every 3:rd frame.

The absTime.QuadPart is much larger with the P4 and the ticksPerSec is the same as the P4:s clock rate ~2.8 billion but on my AMD64 it's only ~3.6 million

I'm going to implement another timer system that handles this better. But if you see anything wrong with my code, I'm all ears :)

EDIT:
I believe I know what the problem is but my guess is that DOUBLE doesn't handle more... My "left part", I forgot the term, of the result of the division was too large. I had an uptime of about 7 days, so I just booted and started the app, this was the result:


39076006 / 3579545 = 38.8529853820801
139087089 / 3579545 = 38.8560791015625
139087141 / 3579545 = 38.8560943603516
139087166 / 3579545 = 38.8561019897461
139098216 / 3579545 = 38.859188079834
139098262 / 3579545 = 38.859203338623
139098287 / 3579545 = 38.8592071533203
139109408 / 3579545 = 38.8623161315918
139109455 / 3579545 = 38.8623275756836
139109483 / 3579545 = 38.8623352050781
139120700 / 3579545 = 38.8654708862305
139120753 / 3579545 = 38.8654861450195
139120779 / 3579545 = 38.8654937744141
139131775 / 3579545 = 38.8685646057129
139131823 / 3579545 = 38.8685760498047
139131849 / 3579545 = 38.8685836791992
139142818 / 3579545 = 38.8716506958008
139142863 / 3579545 = 38.8716621398926
139142894 / 3579545 = 38.8716697692871
139154003 / 3579545 = 38.8747749328613
139154053 / 3579545 = 38.8747863769531
139154079 / 3579545 = 38.8747940063477
139165223 / 3579545 = 38.8779067993164
139165273 / 3579545 = 38.8779220581055
139165298 / 3579545 = 38.8779296875
139176416 / 3579545 = 38.8810348510742
139176464 / 3579545 = 38.8810501098633
139176488 / 3579545 = 38.8810539245605
139187462 / 3579545 = 38.8841209411621
139187509 / 3579545 = 38.8841361999512
139187534 / 3579545 = 38.8841400146484
139198583 / 3579545 = 38.8872299194336
139198632 / 3579545 = 38.8872413635254
139198657 / 3579545 = 38.8872489929199
139209797 / 3579545 = 38.8903617858887
139209849 / 3579545 = 38.8903770446777
139209875 / 3579545 = 38.890380859375
139220855 / 3579545 = 38.8934516906738
139220901 / 3579545 = 38.8934631347656
139220927 / 3579545 = 38.8934707641602
139232037 / 3579545 = 38.8965721130371
139232086 / 3579545 = 38.8965873718262
139232111 / 3579545 = 38.8965950012207
139243085 / 3579545 = 38.8996620178223
139243132 / 3579545 = 38.8996734619141
139243157 / 3579545 = 38.8996810913086
139254257 / 3579545 = 38.9027824401855
139254307 / 3579545 = 38.9027938842773
139254331 / 3579545 = 38.9028015136719
139265899 / 3579545 = 38.9060325622559
139265968 / 3579545 = 38.9060516357422
139265994 / 3579545 = 38.9060592651367
139277038 / 3579545 = 38.9091453552246
139277086 / 3579545 = 38.9091606140137
139277112 / 3579545 = 38.9091682434082
139288251 / 3579545 = 38.9122772216797
139288301 / 3579545 = 38.9122924804688
139288327 / 3579545 = 38.9123001098633
139299281 / 3579545 = 38.9153594970703
139299330 / 3579545 = 38.9153747558594
139299358 / 3579545 = 38.9153823852539
139310290 / 3579545 = 38.9184341430664
139310336 / 3579545 = 38.9184494018555
139310362 / 3579545 = 38.91845703125
139321507 / 3579545 = 38.9215698242188
139321557 / 3579545 = 38.9215812683105
139321582 / 3579545 = 38.9215888977051
139332707 / 3579545 = 38.9246978759766



:P

Share this post


Link to post
Share on other sites
Quote:
Original post by Kija
I don't want to just get the time difference, I need the full time. And the function call is not the problem.

I use this function to get the full time, and also to take the difference in the time, but it's not enough that it just gives the diff. And I use the difference in time to multiply my player movement. So if I get a difference of 0.1 second I move my character 0.1 * units_per_sec.
But the absolute performance counter time in itself is irrelevant, except perhaps if you're using it to communicate with other local processes.
So why not measure the time since starting your application instead? Only calculating frame deltas would be better of course but a double should still be enough to handle a month or so at full precision.

Something along the lines of this perhaps:
class timer {
LARGE_INTEGER base;
double scale;

public:
timer() {
LARGE_INTEGER freq;

QueryPerformanceCounter(&base);
QueryPerformanceFrequency(&freq);

scale = 1.0 / freq.QuadPart;
}

double query() const {
LARGE_INTEGER sample;

QueryPerformanceCounter(&sample);
sample.QuadPart -= base.QuadPart;

return sample.QuadPart * scale;
}
};

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!