on Jun 11th, 2015, 7:46pm, Jack Kelly wrote:| But how exactly does the SLEEP call help the CPU? |
|
Without the Sleep you will be using 100% CPU (at least, 100% of that particular core if it's a multicore processor) for the duration of your delay; 5 seconds in that specific case. That's an awful lot of CPU usage for basically doing nothing at all!
Apart from being wasteful, excessive CPU usage will run a laptop battery down more quickly and/or cause heating which might require the cooling fan to run or the CPU clock frequency to fall.
The Sleep call tells Windows that you have nothing useful to do so it can give the CPU time to another thread or process; if nothing else needs the time the CPU will enter a low-power-consumption idle state.
An alternative approach to writing a delay routine is to use the TIMER statement, which will also keep CPU usage to a minimum:
Code:sub delay seconds
timer seconds*1000, [delay]
wait
[delay]
timer 0
end sub
Richard.