Skip to main content
gamedev.net
🔒 Locked

Timing In Java?

Started by dave 1 reply 1.1k views
Original Post
dave
dave
How do we get the tick count of the cpu so we delay for a couple of seconds in Java. GetTickCount() in windows C returns milliseconds if i'm right. So what function with what imports do it in Java? Thanks. Dave
The Rug
The Rug
See here for currentTimeMillis, or if you need higher accuracy, nanoTime (although that can hit your performance depending on how often you use it.) There are also some 3rd party hi-res timers if you need both accuracy and speed, such as the one in LWJGL (I forget its name.)

You don't need to import anything for the 2 above, just use System.currentTimeMillis() or System.nanoTime()
the rug - funpowered.com
Stani R
Stani R
You can also use the undocumented and unsupported sun.misc.Perf timer.

private static sun.misc.Perf perf;perf = sun.misc.Perf.getPerf();...freq = perf.highResFrequency();	time = perf.highResCounter() * 1000 / freq;



But if you just want to delay, something like sleep(10) ought to do it, depending on what exactly you want to accomplish.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.