time icon indicating copy to clipboard operation
time copied to clipboard

Precision tighter than milliseconds is problematic

Open davedelong opened this issue 4 years ago • 2 comments

It's difficult to deal with precision higher than milliseconds.

I'm attempting to write tests dealing with nanosecond precision and they're failing all over the place. Couple this with the face that DateFormatter won't format anything smaller than milliseconds and maybe Time should just cap things off there.

davedelong avatar Apr 12 '20 17:04 davedelong

Forgive me if I'm telling you stuff you already know, but...

Macs coalesce timers into 15ms windows to save power (and I assume iOS devices are even more aggressive). That makes writing tests for code dealing with smaller units of duration really hard. If you're running into trouble, you may want to try disabling coalescing: https://timoliver.blog/2014/01/25/disabling-timer-coalescing-in-os-x-mavericks/.

I've been bitten by this many times, and I forget this little nugget each time and waste hours debugging.

akshayjshah avatar Jun 26 '20 17:06 akshayjshah

Maybe a way to approach this could be having the system clocks pull their initial date via Date(), but then count and track intervals since then via a ContinuousClock, which would has higher precision than the milliseconds-by-default values coming out of Date.

davedelong avatar Apr 07 '24 02:04 davedelong