Based on ideas presented in link I implemented several different "sleep methods". One of this methods was the "binary sleep", which looks like this:
while (System.currentTimeMillis() < nextTimeStamp)
{
sleepTime -= (sleepTime / 2);
sleep(sleepTime);
}
Because the check if the next time step is already reached takes place at the beginning I, would expect that the method is running too long. But the cummulative distribution of the simulation error (expected time - real time) looks like this: alt text http://img267.imageshack.us/img267/4224/errorvscummulativearran.jpg
Does somebody has an idea why I'm getting this results? Maybe the method System.currentTimeMillis() does not really return the current time?
BR,
Markus
@irreputable
When I made the evaluation I also created a bell curve by using a german statistic program. Because it was not possible to change caption, here is the english translation of all relevant items:
Häufigkeit = frequency
Fehler = error
Mittelwert = average
Std-Abw = standard deviation
alt text http://img694.imageshack.us/img694/2254/bellcurve.jpg
currentTimeMillis() actually give the time accurate to the nearest millisecond on Linux, Mac OS and Windows (and since which versions - I know, for example, that Windows only used to be accurate to the nearest 15/16 milliseconds).
json"(February 26, 2019 12:00:00 AM) and that need to be accessed from android app once device's System. currentTimeMillis() returns exact time.
System. currentTimeMillis() takes about 29 nanoseconds per call while System. nanoTime() takes about 25 nanoseconds.
No it does not. Its young brother System#nanoTime()
has a much better precision than System#currentTimeMillis()
.
Apart from the answers in their Javadocs (click at the links here above), this subject was discussed several times here as well. Do a search on "currenttimemillis vs nanotime" and you'll get under each this topic: System.currentTimeMillis vs System.nanoTime.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With