• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Elapsed time vs sleep
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Elapsed time vs sleep


  • Subject: Re: Elapsed time vs sleep
  • From: Charlie Dickman <email@hidden>
  • Date: Mon, 26 Jul 2010 12:27:48 -0400

As long as the NSTimer firing interval is sufficiently small the NSTimer can be used. If the run loop is stalled for any "significant: time _all_ timers will be inaccurate to some degree. The NSTimer works fine for animation and , e.g., alarm timers and they are consistent across platforms such as Mac Pros, iMacs, iPhones, etc.

On Jul 26, 2010, at 12:12 PM, Kyle Sluder wrote:

> 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

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

  • Follow-Ups:
    • Re: Elapsed time vs sleep
      • From: Sherm Pendley <email@hidden>
    • Re: Elapsed time vs sleep
      • From: Kyle Sluder <email@hidden>
    • Re: Elapsed time vs sleep
      • From: David Duncan <email@hidden>
References: 
 >Elapsed time vs sleep (From: Matt Gough <email@hidden>)
 >Re: Elapsed time vs sleep (From: Charlie Dickman <email@hidden>)
 >Re: Elapsed time vs sleep (From: Kyle Sluder <email@hidden>)

  • Prev by Date: Re: Elapsed time vs sleep
  • Next by Date: Re: Elapsed time vs sleep
  • Previous by thread: Re: Elapsed time vs sleep
  • Next by thread: Re: Elapsed time vs sleep
  • Index(es):
    • Date
    • Thread