29

I know that dispatch_time is the time according to device clock and if the device goes to sleep the clock sleeps too. On the other hand the dipatch_walltime is time according to wall clock, which never goes to sleep. My questions is, is there any difference, performance-wise or other, to use one or the other in different situations? Can somebody give me some more details, because the Apple docs are not exhaustive.

For example I'm writing a Timer class which operates on certain intervals. Also the leeway could be 10 to 30 secs. Which one should I use dispatch_time or dispatch_walltime, performance-wise.

1 Answer 1

44

dispatch_time stops running when your computer goes to sleep. dispatch_walltime continues running because the real world continues running.

So suppose you want to do an action 1 hour from now, but after 5 minutes your computer goes to sleep for 50 minutes. Then:

  • dispatch_walltime will execute an hour from now, 5 minutes after the computer wakes up.

  • dispatch_time will execute after the computer is running for an hour, that is 55 minutes after it wakes up, 1 hour and 50 minutes from now.

1
  • 1
    What about time jumps? When daylight saving is setting back 1 hour?
    – Lothar
    Jul 27, 2019 at 11:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.