• 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: 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

  • Follow-Ups:
    • Re: Elapsed time vs sleep
      • From: Charlie Dickman <email@hidden>
References: 
 >Elapsed time vs sleep (From: Matt Gough <email@hidden>)
 >Re: Elapsed time vs sleep (From: Charlie Dickman <email@hidden>)

  • Prev by Date: -resolveWithTimeout never completes . . .
  • 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