Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / High accuracy timer

Author
Message
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 25th Jun 2006 11:25
I need something more than dbTimer(), what are my options? I found this...

[href]null[/href]http://www.decompile.com/html/windows_timer_api.html

but I cant figure out how to get it to work with dark sdk (mainly how to get sdk to print the results of a "large integer".

I wish the damn patch would come out, u6 had a neat thing called perftimer()...

All you need is zeal
APEXnow
Retired Moderator
21
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 25th Jun 2006 19:36
In your application's initial function that only gets called once, do



then, when ever you eant to get the exact time in ms, do



The QueryPerformanceFrequency and Counter functions are High precision functions. Can't get any more accurate than that.

Paul.


Home of the Cartography Shop - DarkBASIC Professional map importer
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 26th Jun 2006 08:02 Edited at: 26th Jun 2006 17:50
Awesome, thanks bud!

*Edit

Doh, I didnt mean accurate, I meant I needed a more precise timer. Is there anyway to count time smaller than ms?

The above code you posted works, but its identical to dbTimer()

All you need is zeal
APEXnow
Retired Moderator
21
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 26th Jun 2006 18:10
Zeal, the (*1000) is to convert from micro pulses to Milliseconds. If you remove that multiplaction, that will be the highest accuracy capable with your hardware.

Paul.


Home of the Cartography Shop - DarkBASIC Professional map importer
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 27th Jun 2006 12:33 Edited at: 27th Jun 2006 12:34
Cool the new timer is working great! However, im having a new problem.

For some bizzare reason, im noticing little spikes (about 16ms with the dbTimer() and 1-5ish ms with perfTimer() ). The spikes only happen if you try and clock particular functions (usually the more intense ones), but the spikes are ALWAYS for the exact same amount it seems (thus I dont think its the code causing the spike, but something else).

Is it normal for these timer functions to sometimes cause spikes like this? Even if it is, why does it seem to only happen when I time particular functions? If I just time empty space (ttStart(); ttStop(); ) I never see these spikes. And I dont think it cant be the systems (code) itself, because like I said, I get the same spike when I time completely different systems (16ms with dbTimer() 5ish with perfTimer()).

Could it be my timer code? Here it is...



All you need is zeal
APEXnow
Retired Moderator
21
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 27th Jun 2006 13:24
Zeal, 16ms, and even 1-5 ms is very very small. Remeber that there are 1000ms in 1 second. The odds are that when a function is called between your start time and end time, it may be possible for CPU interrupts to occur as well, for dealing with input signals, low-level OS management, memory pool swapping etc. It really all depends on what function you are calling between the ttStart event and the ttStop event. But the timer code itself seems sound.

Paul.


Home of the Cartography Shop - DarkBASIC Professional map importer
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 27th Jun 2006 14:10
What. The. Heck.

Look at this code...



The part

int timeStop = dbTimer() + 3;
while ( dbTimer() < timeStop ) {

}

should waste 3 ms (MAYBE give or take 1-2ms). Well I dont know about you but when I run the above code tt returns a spike of... you guessed it, 16ms.

Am I missing something stupid? I have to be...

All you need is zeal
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 27th Jun 2006 14:23 Edited at: 27th Jun 2006 14:26
WHoa... Could it be possible it has something to do with windows media player? I swear while windows meadia player is OPEN, it WORKS! When wmp is open (not even playing music) I swear it gives accurate results. As soon as I close wmp, the above program goes back to giving 16ms.

Perhaps is this just an error then? Maybe 16ms isnt really passing, but rather dbTimer() is returning bogus results?

Explain that WMP thing tho... lol

***

That is just the craziest thing I have ever seen. I just checked it again, WMP open in the background, ttSpikes at 3ms, as it should. Close WMP (dont even have to recompile), and BAM ttSpikes at 16ms exactly.

Im gonna get some sleep, maybe my eyes are playing tricks on me. Will check this again in the morning.

All you need is zeal
APEXnow
Retired Moderator
21
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 27th Jun 2006 14:37
I maybe missing the point, but dbTimer uses the GetTickCount function under Windows, which I know to have a pretty lousy resolution. I found this article which may prove useful in finding a better way to measure time more accurately.

http://www.mvps.org/directx/articles/selecting_timer_functions.htm

Paul.


Home of the Cartography Shop - DarkBASIC Professional map importer
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 27th Jun 2006 20:02
Wow that was a good read, thanks for the link.

And just to confirm, this all WAS caused by windows media player, or to be more specific, crappy results from dbTimer(). I still cant get over that lol, can anyone else confirm they get the same results? Like I said, dbTimer() seems to be off by roughly 16ms IF and ond only if WMP is CLOSED. When its running, dbTimer() works fine.

The moral of the story is, dbTimer() IS THE DEVIL!!!!!1!!1 Im using QueryPerformanceFrequency from here on out.

All you need is zeal
APEXnow
Retired Moderator
21
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 27th Jun 2006 20:15
w00t, glad you got it licked!!

Paul.


Home of the Cartography Shop - DarkBASIC Professional map importer
Kaiyodo
18
Years of Service
User Offline
Joined: 24th Aug 2005
Location: UK
Posted: 27th Jun 2006 23:31 Edited at: 27th Jun 2006 23:32
Edit : Oops, posted in wrong thread
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 28th Jun 2006 15:39 Edited at: 28th Jun 2006 19:14
Follow up question - Is there any easyway to print the value of a double or longlong? dbStr cant seem to convert it

All you need is zeal
Kaiyodo
18
Years of Service
User Offline
Joined: 24th Aug 2005
Location: UK
Posted: 29th Jun 2006 11:39
You could use sprintf to print it to a string first ..



Whenever I'm using QueryPerformanceCounter I tend to throw away the high part anyway as the chances of it changing while your program is running is pretty slim. It's easy to work with that way

Kaiyodo.
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 29th Jun 2006 13:34
I may have missed something but what exactly does OutputDebugString(string); do?

Where is it "outputting" the results so I can see them? Is there anyway to print the results to a location on the screen so I can read them? Like dbText()

All you need is zeal
Kaiyodo
18
Years of Service
User Offline
Joined: 24th Aug 2005
Location: UK
Posted: 29th Jun 2006 15:58
OutputDebugString outputs to the debug console if you're running through the debugger. Just feed the 'string' variable in my example into dbText() if you want to display it on the screen.

Kaiyodo.
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 29th Jun 2006 18:44
Hmm thats not a string tho, its just an array of chars, isnt it? How could I print that to the screen?

All you need is zeal
APEXnow
Retired Moderator
21
Years of Service
User Offline
Joined: 15th Apr 2003
Location: On a park bench
Posted: 29th Jun 2006 18:56 Edited at: 29th Jun 2006 18:56
It's a pointer to a string of characters. sprintf formats the number into 'string', and OutputDebugString, displays it in the debug console.

Paul.


Home of the Cartography Shop - DarkBASIC Professional map importer
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 29th Jun 2006 19:54 Edited at: 29th Jun 2006 19:55
Yeah I see it in the debug console but im still wondering about converting it into something dbStr() can handle. Hell even for the c++ string class it was a pain in the ass to figure it out ( const_cast<char*>(myString.c_str()) ), <---- thats crazy enough

All you need is zeal
Kaiyodo
18
Years of Service
User Offline
Joined: 24th Aug 2005
Location: UK
Posted: 30th Jun 2006 21:51
You shouldn't have to do anything funky to be able to use dbText to print that out on the screen, no conversion is required.



Passing a char[] is the same as passing a char * in C.

Kaiyodo.
Zeal
21
Years of Service
User Offline
Joined: 10th Oct 2002
Location: Colorado Springs, CO
Posted: 1st Jul 2006 01:38
Holy crap!!

After the nightmare that was trying to figure out how to get dbText to accept a string object ( const_cast<char*>(myString.c_str()) wtfomgzor ), I just assumed THIS would require something simillar.

Hurray for simplicity!

All you need is zeal

Login to post a reply

Server time is: 2024-05-25 17:07:24
Your offset time is: 2024-05-25 17:07:24