Re: Elapsed time vs sleep
Re: Elapsed time vs sleep
- Subject: Re: Elapsed time vs sleep
- From: Kyle Sluder <email@hidden>
- Date: Mon, 26 Jul 2010 09:12:05 -0700
On Jul 26, 2010, at 8:32 AM, Charlie Dickman <email@hidden> wrote:
> Try using an NSTimer with a repeating timeout interval of, say, .001 (or anything smaller than your required accuracy), and countdown your time delta by the same amount each time the NSTimer fires and when you get to zero you'll have what you need.
NSTimer is not suitable for timekeeping of any significant resolution. NSTimer works by comparing the current time at the top of the runloop with the last time the timer was fired. Obviously, this is highly susceptible to anything that prevents the runloop from running at at least the timer interval—which on a modern multitasking operating system is quite likely.
mach_absolute_time is certainly the way to go. The best advice I've seen out there is to listen for sleep/wake notifications from IOKit and record the system time there to figure out how much time has elapsed between the two.
--Kyle Sluder_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden