Timing

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
vhong
Posts: 1
Joined: Thu Jan 19, 2006 4:14 pm

Timing

Post by vhong »

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!
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Re: Timing

Post by jimparis »

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.
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.
urchin
Posts: 121
Joined: Thu Jun 02, 2005 5:41 pm

Post by urchin »

sceKernelLibcGettimeofday() definitely gives microseconds.
chp
Posts: 313
Joined: Wed Jun 23, 2004 7:16 am

Post by chp »

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

Example:

Code: Select all

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
PeterM
Posts: 125
Joined: Sat Dec 31, 2005 7:25 pm
Location: Edinburgh, UK
Contact:

Post by PeterM »

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.
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

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.
PeterM
Posts: 125
Joined: Sat Dec 31, 2005 7:25 pm
Location: Edinburgh, UK
Contact:

Post by PeterM »

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!
chp
Posts: 313
Joined: Wed Jun 23, 2004 7:16 am

Post by chp »

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
PeterM
Posts: 125
Joined: Sat Dec 31, 2005 7:25 pm
Location: Edinburgh, UK
Contact:

Post by PeterM »

Yep I must have done something very silly - I'll go back and recheck.
Post Reply