3

I've discovered through extensive printf-debugging that System.nanoTime() isn't actually what it purports to be: a monotonically increasing long representing nanoseconds with at least millisecond accuracy.

I've made two calls to System.nanoTime() about 14 hours apart, and yet the time delta returned is about 13.1 hours.

What might be the reason for this inaccuracy?

MitchellSalad
  • 4,171
  • 8
  • 23
  • 24
  • Possible answer? http://stackoverflow.com/questions/5023647/java-system-nanotime-huge-difference-in-elapsed-time System.currentTimeMillis() will give you the most accurate possible elapsed time in milliseconds since the epoch, but System.nanoTime() gives you a nanosecond-precise time, relative to some arbitrary point. http://stackoverflow.com/questions/11452597/precision-vs-accuracy-of-system-nanotime – EtherPaul Apr 11 '17 at 20:09
  • How did you call it 14 hours apart? How did you measure exactly 14 hours? Because if you're using a timer, alarm, or sleep, Doze is going to kick your butt. – Gabe Sechan Apr 11 '17 at 20:40
  • @Gabe, I simply have an activity that prints the nanotime when I open it. I opened the app at 10pm, then again at noon the next day – MitchellSalad Apr 12 '17 at 00:45

0 Answers0