forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Timing

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
vhong



Joined: 19 Jan 2006
Posts: 1

PostPosted: Thu Jan 19, 2006 4:20 pm    Post subject: Timing Reply with quote

Hello,

I've recently gotten into PSP development, and I'm totally loving it! I have one question which I have not been able to find any answers for.

From the examples and such I've seen, the only way to do timing is through sceKernelLibcTime, which returns seconds. Is there any way to retreive time in milliseconds?

I'd like to do some simple 2d animations properly, but I've been unable to find any examples/documentation on precise timing.

Thanks in advance!
Back to top
View user's profile Send private message
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Thu Jan 19, 2006 5:07 pm    Post subject: Re: Timing Reply with quote

vhong wrote:
From the examples and such I've seen, the only way to do timing is through sceKernelLibcTime, which returns seconds. Is there any way to retreive time in milliseconds?
clock() and gettimeofday() should both give you microseconds.
Quote:
I'd like to do some simple 2d animations properly, but I've been unable to find any examples/documentation on precise timing.
I'd recommend using SDL, there's plenty of documentation and example code on the net.
Back to top
View user's profile Send private message
urchin



Joined: 02 Jun 2005
Posts: 121

PostPosted: Thu Jan 19, 2006 7:06 pm    Post subject: Reply with quote

sceKernelLibcGettimeofday() definitely gives microseconds.
Back to top
View user's profile Send private message
chp



Joined: 23 Jun 2004
Posts: 313

PostPosted: Thu Jan 19, 2006 7:23 pm    Post subject: Reply with quote

I've more recently started using the realtime clock. This gives you a fixed high-frequency timer and should be very reliable.

Example:
Code:

u64 last;
u32 tickFrequency = sceRtcGetTickResolution();
sceRtcGetCurrentTick(&last);

while (1)
{
 // get delta-time for current frame
 u64 curr;
 sceRtcGetCurrentTick(&curr);

 float deltaTime = (curr-last) / (float)tickFrequency;
 last = curr;

 // ... do whatever you want with the delta-time
}

_________________
GE Dominator
Back to top
View user's profile Send private message
PeterM



Joined: 31 Dec 2005
Posts: 125
Location: Edinburgh, UK

PostPosted: Sat Jan 21, 2006 3:58 am    Post subject: Reply with quote

chp wrote:
sceRtcGetCurrentTick()
I've no idea why, but when I tried using this function (before giving up and switching to clock()), it was taking a long time to finish (around .2 seconds per call!)

Perhaps I was doing something silly, but I'm pretty sure not.
Back to top
View user's profile Send private message Visit poster's website
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Sat Jan 21, 2006 4:18 am    Post subject: Reply with quote

Well the rtc stuff is probably sitting on an external bus so it perhaps needs to to query it. Maybe :P One thing you can possibly use is the profile registers though I don't think they are available when not running in kernel mode.
Back to top
View user's profile Send private message
PeterM



Joined: 31 Dec 2005
Posts: 125
Location: Edinburgh, UK

PostPosted: Sat Jan 21, 2006 4:25 am    Post subject: Reply with quote

It's no big deal now, since clock() works fine in Quake, but I assume that clock() probably just calls sceRtcGetCurrentTick() internally.

I must be doing something wrong there - I really didn't expect a high res timer query to take so long!
Back to top
View user's profile Send private message Visit poster's website
chp



Joined: 23 Jun 2004
Posts: 313

PostPosted: Sun Jan 22, 2006 7:21 am    Post subject: Reply with quote

I did a test of your claim, and I can safely say that it's false. :) Here's some info over the different methods used for timing and how often they can get called:

sceRtcGetCurrentTick() - around 511900 calls per second, or 1.953 microseconds per call.

gettimeofday() - around 120310 calls per second, or 8.311 microseconds per call.
4 times slower than using the RTC.

clock() - around 512500 calls per second, or 1.951 microseconds per call.
Actually slightly faster than the RTC, but I suspect this is because it returns a 32-bit value.

I don't know about you, but I'm sticking with the RTC timer mostly because it offers 64 bit values, and I like using native interfaces. Using gettimeofday() should be a big no-no if you want proper resolution. :)
_________________
GE Dominator
Back to top
View user's profile Send private message
PeterM



Joined: 31 Dec 2005
Posts: 125
Location: Edinburgh, UK

PostPosted: Sun Jan 22, 2006 8:03 am    Post subject: Reply with quote

Yep I must have done something very silly - I'll go back and recheck.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group