My point is that you have to ask for the time before every sleep. I don't see your code, so you might already be doing that.
I've posted my code.
Of course, if you spawn an external process for querying the time, then that's slow, so don't do that.
Starting up a new process takes a short, predictable time. (The time to start the external "play" utility and start playing the sound is less than ~1 ms, which is negligible for my purposes.) My problem is latency, which is a long and unpredictable time period, often hundreds of milliseconds before my process gets control back from xscreensaver.