Re: NSTimer fires ~0.0045 seconds early?
Re: NSTimer fires ~0.0045 seconds early?
- Subject: Re: NSTimer fires ~0.0045 seconds early?
- From: Jonathan Stimmel <email@hidden>
- Date: Sun, 5 Aug 2001 22:20:08 -0700
- Mail-followup-to: Jonathan Stimmel <email@hidden>, email@hidden
On Sun, Aug 05, 2001 at 09:22:52PM -0700, Brant Vasilieff wrote:
>
When I schedule my timer, It appears to sometimes fire early. So I
>
stored the desired date, and fetched the interval within timerFired:.
>
If it had been negative, than that would have implied that the timer
>
fired later than requested. What I ended up with surprised me. The
>
interval was not only positive, but further away from zero than I
>
thought. I ended up with numbers of 0.004 and 0.0045. Isn't
>
NSTimeInterval a double?
Whether it's a float or a double, any timer still has a limited
granularity, particularly on a multithreaded OS (where you can't
be guaranteed that your thread is running at the exact millisecond
you want to do something). Take a look at the docs for NSTimer;
they clearly state, "the effective resolution of the time interval
for an NSTimer is limited to on the order of 50-100 milliseconds".
I'd say that you're doing quite well to get a 5ms resolution
(on an unloaded system, I assume; how's it do when it has to
compete for CPU time?)