Re: Elapsed time vs sleep
Re: Elapsed time vs sleep
- Subject: Re: Elapsed time vs sleep
- From: Charlie Dickman <email@hidden>
- Date: Mon, 26 Jul 2010 11:32:59 -0400
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.
On Jul 26, 2010, at 4:56 AM, Matt Gough wrote:
> I need to calculate (with an accuracy of 0.1 of a second) a real-time time interval. This interval should:
>
> 1. Not be affected by whether the system has been put to sleep and woken up while timing. (i.e If I start the timer then sleep the Mac for an hour and wake it up again, my interval should be just over 60 minutes)
> 2. Not be affected by changes to the wall clock. (i.e If I start the timer, leave it for an hour and then set the wall clock back to the start time, my interval should be just over 60 minutes and not zero)
>
> Up to now, I have been using mach_absolute_time (which satisfies condition 2), but had not noticed that it could not satisfy condition 1. There are several other higher level versions (i.e Uptime, Microseconds), but they all seem to call down to mach_absolute_time.
>
> Obviously all the wall-clock based based (NSDate date], CFAbsoluteTimeGetCurrent) are also out of bounds due to condition 2.
>
> Have I missed something obvious, or is this just not doable?
>
> Thanks
>
> Matt Gough_______________________________________________
>
> 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
Charlie Dickman
email@hidden
_______________________________________________
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