measure / limit the function execution time, cross-platform
Project description
timework
measure / limit the function execution time, cross-platform
Install
pip install timework
Usage
import timework as tw
Statement with
timework.Stopwatch
Todo
Decorator @
Todo: read docstrings and tests for more details
timework.timer
measuring the execution time.
import logging
@tw.timer(logging.warning)
def timer_demo_a():
i = 0
while i < 2 ** 23:
i += 1
return i
@tw.timer(print, detail=True)
def timer_demo_b():
i = 0
while i < 2 ** 24:
i += 1
return i
a = timer_demo_a()
b = timer_demo_b()
print(a, b)
WARNING:root:timer_demo_a: 0.496672 seconds used
START: Tue Feb 18 15:06:45 2020
FINISH: Tue Feb 18 15:06:46 2020
timer_demo_b: 0.989352 seconds used
8388608 16777216
timework.limit
limiting the execution time.
timework.TimeError
only contains:
TimeError.message
string, <decorated function name>: <timeout> seconds exceededTimeError.result
None, unusedTimeError.detail
None, unused
@tw.limit(3)
def limit_demo(m):
i = 0
while i < 2 ** m:
i += 1
return i
try:
s = limit_demo(4)
except tw.TimeError as e:
print(e)
else:
print('result:', s)
try:
s = limit_demo(30)
except tw.TimeError as e:
print(e)
else:
print('result:', s)
result: 16
limit_demo: 3 seconds exceeded
License
MIT License © bugstop
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
timework-0.3.2.tar.gz
(5.5 kB
view hashes)