What do you guys use for your Hi-rez timers?

I stumbled upon
import sun.misc.Perf;

because it allows me to get the frequency.
Perf.getPerf().highResFrequency()

Here’s the timer call…
Perf.getPerf().highResCounter();

This seems to work fine when running my app in Windows, Mac and Linux.

In the new NetBeans IDE 6.7 it displays the below warning about using this library.
warning: sun.misc.Perf is Sun proprietary API and may be removed in a future release

So I’m not sure if i should be concerned.

I was trying to use System.nanoTime() but there’s no call to get the frequency. Need the frequency so that the timing is consistent across os’s and platforms.

Is anyone using a different timer system?

I use LWJGL’s timer.

Cas :slight_smile:

Need the frequency so that the timing is consistent across os’s and platforms.

No, you don’t need that. It’s always in nano seconds.

I also use LWJGL’s timer. It’s sufficiently accurate and far more robust than QPC-based timers (like perf and nano).

I know there is a better timer in JMF but including it only to benefit of this feature is a bit too much on my view. Someone here spoke some months ago about implementing an high resolution timer for JOGL, I don’t know if it has been included in JOGL 2.

Wouldn’t that be a wrapper for a timer that’s currently available?

Sort of but not quite. LWJGL’s timer uses a TGT (time get time) based timer on Windows, which provides 1msec accuracy (which is good enough for games - all Quake engine based titles are using this kind of timer for example). On Linux and Mac currentTimeMillis() is used since it happens to provide a 1msec resolution out of the box (whereas it’s 50-55 on Win9x, 10 on NT/2k, 15 on XP, and whatever on Vista).

I think JMF probably uses timeGetTime on windows but I couldn’t be sure. It’d make sense coz that’s what it’s for.

Cas :slight_smile:

I see now. Thanks for the info!

I simply use currentTimeMillis :stuck_out_tongue:

ps: I have never seen so poor (50-55) resolution timer even on window It is more 16ms/17ms wichs is enought until you dont go over 60fps

I’ve seen 50ms on windows 9x - it sucks so bad its not even funny

Yes, it’s really 50-55 (or more accurately: randomly jumping back n forth to either 50 or 55) on Win9x. My adaptive yield throttle timing code (4k) was build to deal with timers as bad as this for example.

Well, you really need 1msec accuracy if you want to cap the framerate and sleep a bit while you’re at it.

If you go uncapped a mediocre timer will do, if you’re using damped deltas, that is. However, since the vast majority of sold machines are laptops and the like these days, preserving energy is pretty important. There is really no point in draining the battery at 100% usage, if 5% usage would have been sufficient.

ok, I know this timer really sucks on window… did not know that it can be so poor, only seen 16.5 ms accuracy until now.

[quote]If you go uncapped a mediocre timer will do, if you’re using damped deltas, that is. However, since the vast majority of sold machines are laptops and the like these days, preserving energy is pretty important. There is really no point in draining the battery at 100% usage, if 5% usage would have been sufficient.
[/quote]
can be really usefull for winter days :slight_smile: