• Guest, The rules for the P & N subforum have been updated to prohibit "ad hominem" or personal attacks against other posters. See the full details in the post "Politics and News Rules & Guidelines."

How does coding for an alarm clock work?

IronWing

No Lifer
Jul 20, 2001
57,605
9,919
126
I noticed that the battery on my iPhone drains faster if I set the alarm clock. Does a script constantly check to see if it’s time to ring the alarm?
 

Steelbom

Senior member
Sep 1, 2009
327
7
81
I've done a fair bit of programming, a bit on iOS in particular. I don't really know the answer, but it doesn't seem likely that the alarm clock will drain your iPhone (noticeably) faster. I suspect the app would be checking the time periodically but again, not so much that it should hurt battery life in any noticeable way.
 

KentState

Diamond Member
Oct 19, 2001
7,689
129
106
Just a guess, but an alarm could be a thread that is asleep. The CPU will continue to run cycles regardless and wake the thread when it's time to go off. Since the pooling rate to wake the thread is pretty low, the CPU consumes power mostly for active tasks. A button press or anything else to wake the screen is similar in that it's pooling for an event.

If you think about it, a phone CPU might be running at 100Mhz minimum. Even then that's 100 million cycles per second that can go somewhere. Checking if a thread should wake is a very small amount of that.
 

ASK THE COMMUNITY