What would be better ?
time.sleep(delayTime)
or
select.select([],[],[],delayTime)
Are they equivalent ? Is select more efficient?
Python has built-in support for putting your program to sleep. The time module has a function sleep() that you can use to suspend execution of the calling thread for however many seconds you specify.
The Timer is another method available with Threading, and it helps to get the same functionality as Python time sleep. The working of the Timer is shown in the example below: Example: A Timer takes in input as the delay time in Python in seconds, along with a task that needs to be started.
Sleeping time of python is three times six, which is equal to 18 hours. Awake time of python is the unshaded portion, which contains one quarter of the circle. So awake time 6×1=6 hours.
Python 3 - time sleep() MethodThe method sleep() suspends execution for the given number of seconds. The argument may be a floating point number to indicate a more precise sleep time.
Pretty simple to hackup a test in python with called to timeit
, but I love ipython for quick tests (http://ipython.org/). Here's my results:
$ ipython
import time,select
%timeit time.sleep(0)
1000000 loops, best of 3: 655 ns per loop
%timeit select.select([],[],[],0)
1000000 loops, best of 3: 902 ns per loop
But if you don't have access to ipython, and would prefer native timeit
from command line:
$ python -m timeit -s "import time,select" "time.sleep(0)"
1000000 loops, best of 3: 0.583 usec per loop
$ python -m timeit -s "import time,select" "select.select([],[],[],0)"
1000000 loops, best of 3: 0.777 usec per loop
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With