I've used profile on functions in my Python script to get their execution time, and I've used the Unix time command to get the real, user and sys time of the script overall, but I can't find how to measure the time spent waiting for I/O in Python.
In my script I query various database, can I measure the time it takes to send and receive information?
you can use a Decorator like this that allows you to measure the execution times of dedicated methods :
import time
def measure_time(f):
def timed(*args, **kw):
ts = time.time()
result = f(*args, **kw)
te = time.time()
print '%r (%r, %r) %2.2f sec' % \
(f.__name__, args, kw, te-ts)
return result
return timed
You can use it like this :
@measure_time
def foo():
#content of function
note that f.__name__ return the name of function ! (in this case 'foo')
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