| View previous topic :: View next topic |
| Author |
Message |
vhong
Joined: 19 Jan 2006 Posts: 1
|
Posted: Thu Jan 19, 2006 4:20 pm Post subject: Timing |
|
|
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 |
|
 |
jimparis
Joined: 10 Jun 2005 Posts: 1179 Location: Boston
|
Posted: Thu Jan 19, 2006 5:07 pm Post subject: Re: Timing |
|
|
| 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 |
|
 |
urchin
Joined: 02 Jun 2005 Posts: 121
|
Posted: Thu Jan 19, 2006 7:06 pm Post subject: |
|
|
| sceKernelLibcGettimeofday() definitely gives microseconds. |
|
| Back to top |
|
 |
chp
Joined: 23 Jun 2004 Posts: 313
|
Posted: Thu Jan 19, 2006 7:23 pm Post subject: |
|
|
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 |
|
 |
PeterM
Joined: 31 Dec 2005 Posts: 125 Location: Edinburgh, UK
|
Posted: Sat Jan 21, 2006 3:58 am Post subject: |
|
|
| 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 |
|
 |
TyRaNiD
Joined: 18 Jan 2004 Posts: 918
|
Posted: Sat Jan 21, 2006 4:18 am Post subject: |
|
|
| 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 |
|
 |
PeterM
Joined: 31 Dec 2005 Posts: 125 Location: Edinburgh, UK
|
Posted: Sat Jan 21, 2006 4:25 am Post subject: |
|
|
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 |
|
 |
chp
Joined: 23 Jun 2004 Posts: 313
|
Posted: Sun Jan 22, 2006 7:21 am Post subject: |
|
|
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 |
|
 |
PeterM
Joined: 31 Dec 2005 Posts: 125 Location: Edinburgh, UK
|
Posted: Sun Jan 22, 2006 8:03 am Post subject: |
|
|
| Yep I must have done something very silly - I'll go back and recheck. |
|
| Back to top |
|
 |
|