A package used to set time limits.
Project description
timework
A package used to set time limits.
Install
pip install timework
Usage
import timework as tw
import logging
r = tw.ResultHandler()
@tw.timer(r)
def timer_demo_a():
i = 0
while i < 2 ** 23:
i += 1
return i
@tw.timer(r, out=print)
def timer_demo_b():
i = 0
while i < 2 ** 24:
i += 1
return i
@tw.timer(r, out=logging.warning)
def timer_demo_c():
i = 0
while i < 2 ** 25:
i += 1
return i
@tw.limit(3)
def limit_demo(m):
i = 0
while i < 2 ** m:
i += 1
return i
@tw.iterative(r, 1)
def iterative_demo(max_depth):
i = 0
while i < 2 ** max_depth:
i += 1
return max_depth, i
timer_demo_a()
timer_demo_b()
timer_demo_c()
print(r.value, end='\n\n')
try:
s = limit_demo(4)
except Exception as e:
print(e, end='\n\n')
else:
print(s)
try:
s = limit_demo(30)
except Exception as e:
print(e, end='\n\n')
else:
print(s)
try:
r.clean()
iterative_demo(max_depth=10)
except Exception as e:
print(e)
finally:
print(r.value, end='\n\n')
try:
r.clean()
iterative_demo(max_depth=25)
except Exception as e:
print(e)
finally:
print(r.value, end='\n\n')
timer_demo_b: 0.990397 seconds used
WARNING:root:timer_demo_c: 1.96071 seconds used
[0.49068570137023926, 0.9903974533081055, 1.9607088565826416]
16
limit_demo: 3 seconds exceeded
[(1, 2), (2, 4), (3, 8), (4, 16), (5, 32), (6, 64), (7, 128), (8, 256), (9, 512), (10, 1024)]
iterative_deepening: 1 seconds exceeded
[(1, 2), (2, 4), (3, 8), (4, 16), (5, 32), (6, 64), (7, 128), (8, 256), (9, 512), (10, 1024), (11, 2048), (12, 4096), (13, 8192), (14, 16384), (15, 32768), (16, 65536), (17, 131072), (18, 262144), (19, 524288)]
Process finished with exit code 0
License
MIT 漏 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.1.0.tar.gz
(3.1 kB
view hashes)