High Resolution Timers

BlitzMax Forums/BlitzMax Programming/High Resolution Timers

Damien Sturdy(Posted 2007) [#1]
Hi Guys n Gals,

I was playing around a bit last night and came up with something relatively useful- a high resolution timer class for Win32.

It can be seen here:

http://www.blitzbasic.com/codearcs/codearcs.php?code=1909

If you Linux/MacOS users can wrap these same functions to make it Cross Platform, that'd benefit everyone here.

Also, any problems, or potential probs, lemme know :D


[edit]

There's some other code on the forum by REDi which seems remarkably similar. Whilst I have seen this code before, It wasn't around when I coded mine! :O


Grey Alien(Posted 2007) [#2]
I don't know how yours works but regretably I'm now dubious of such timers due to Dual core chips and different CPU stepping blah blah having a dodgy affect on such times...:-(


Damien Sturdy(Posted 2007) [#3]
I have dual core, and this seems to work on mine and non-dual core. You have to use the provided commands to get an accurate frequency reading and then use that *carefully* (long int maths- avoid division where possible. Even I used more division than I would have liked...) to get accurate results.


Grey Alien(Posted 2007) [#4]
yeah I'm not trying to dis your code dude, I just looked into it a while ago and kept finding info like this:

http://www.virtualdub.org/blog/pivot/entry.php?id=106


Gabriel(Posted 2007) [#5]
All you have to do is use TimeGetTime() as a backup and if QueryPerformanceCounter appears to have jumped a few seconds compared to the value returned by TimeGetTime(), reset it with what you got from TimeGetTime(). You still get the nanosecond accuracy, but you can spot and correct jumps.


Grey Alien(Posted 2007) [#6]
interesting!


Damien Sturdy(Posted 2007) [#7]
Nono, I didn't think you were Grey :) That was an interesting read.

I'll do more testing of my own and try it on a laptop or two. the TimeGetTime trick sounds neat for a failsafe :)