measure / limit execution time using with-statements or decorators, cross-platform
pip install timework
import timework as tw
measure execution time
with tw.Stopwatch() as s:
s.split()
s.stop()
s.restart()
s.pause()
s.resume()
s.get_sec()
s.get_hms()
get_sec() get_hms() restart() pause()
resume() split() stop()
measure execution time
@tw.timer(logging.warning)
def your_function():
...
output: A function object that specifies where to log messages.
For example: print. timework.nil does not log messages.
detail: A boolean value, whether to print start and end time.
This argument must be passed using keywords.
limit execution time
@tw.limit(3)
def your_function():
...
timeout: This argument sets the timeout limit of the decorated
function. Once the run time of the process reaches
[timeout] seconds but not yet finishes, then raise
TimeoutException and stop the inner function.
MIT License © bugstop