Returns the current value of the most precise available system timer, in nanoseconds.

This method can only be used to measure elapsed time and is not related to any other notion of system or wall-clock time. The value returned represents nanoseconds since some fixed but arbitrary time (perhaps in the future, so values may be negative). This method provides nanosecond precision, but not necessarily nanosecond accuracy. No guarantees are made about how frequently values change. Differences in successive calls that span greater than approximately 292 years (2^63 nanoseconds) will not accurately compute elapsed time due to numerical overflow.

look at the last bit. i mean, seriously, who is going to run a java app for 300 years a computer doesn't even live that long, let alone stay up

Even so, System.nanoTime() doesn't work well on computers with dual core processors because it sometimes gets the time from the wrong core. That's why System.nanoTime() is evil (as discussed in some other thread).

For example Windows XP Service Pack 2 changed things to use the power management timer (PMTimer) rather than the processor timestamp-counter (TSC) due to problems with the TSC not being synchronized on different processors in SMP systems, and due the fact its frequency can vary (and hence it's relationship to elapsed time) based on power-management settings.

What about using NanoTimings if your data is loaded in RAM? Wouldn't that be the best solution regarding the RAM running @ averaging 9ns, would it? And for disk storage, this wouldn't be the case, averaging the HDD r/w access to 10ms....

I think the problem with the LWJGL timer EgonOlsen is referring to (I've hit the same problem too) doesn't have anything to do with the timing method itself but is totally due to a VM bug (which I haven't been able to isolate though). I've never seen the same problem with System.currentTimeMillis.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org