Does SetTimer use polling to track the time? Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
william_ahk
Posts: 496
Joined: 03 Dec 2018, 20:02

Does SetTimer use polling to track the time?

Post by william_ahk » 21 Mar 2024, 20:56

How is SetTimer actually implemented? Does it calculate a future timestamp for the next activation and periodically check if the current timestamp is >= than that timestamp? Is there any difference in energy cost between the two below?

Code: Select all

; A
SetTimer fn, -(60-A_Sec)*1000
; B
SetTimer chk, 1000

chk() {
	if A_Sec != "00"
		return
	SetTimer chk, 0
	fn()
}

fn() {
	MsgBox "It's " A_Hour ":" A_Min ":" A_Sec
}

And how does it compare to Sleep (irrespective of threading)?

Code: Select all

Sleep (60-A_Sec)*1000
fn()

lexikos
Posts: 9593
Joined: 30 Sep 2013, 04:07
Contact:

Re: Does SetTimer use polling to track the time?  Topic is solved

Post by lexikos » 22 Mar 2024, 02:56

If there is an energy cost but you have no way to observe or measure it, why care? If you have a way to measure it, then do that. Making assumptions about how something of this nature performs based on how it is implemented is a poor idea. If you're just curious about how it works, you can (try to) read the source code.

Performing a periodic check in script is not comparable to performing a periodic check in C++. Script involves much more overhead, and likely also spams ListLines. Even so, I would use whichever approach is easier to implement (which happens to be the more efficient one, "A").

Post Reply

Return to “Ask for Help (v2)”