Search code examples
pythonsleep

Is time.sleep() a CPU bound operation?


I've recently read in this asyncio article

time.sleep() is a CPU bound operation

I usually connected with "CPU bound" that the CPU is actually doing something. So if one has time.sleep(60) in a program (A) and then executes

A: Gets 1 second
B: Gets 59 seconds (uninterrupted)
A: Finished or not?

I always thought about timers being IO. Is that wrong? Or are timers just something special, so that they don't fit into the "IO-bound" / "CPU bound" schema?


Solution

  • It's not. That article is misusing terminology.

    A CPU-bound operation is one whose speed is limited by the speed of CPU execution, as opposed to the speed of memory access or network round trips or some other factor. time.sleep is not such an operation. A faster CPU does not make time.sleep any faster.