A simple stopwatch for measuring code performance
Project description
Stopwatch
A simple stopwatch for measuring code performance.
Examples
import time
from stopwatch import Stopwatch, profile
stopwatch = Stopwatch()
stopwatch.start()
time.sleep(3.0)
stopwatch.stop()
print(stopwatch.elapsed) # 3.003047182224691
with Stopwatch(name='outer') as outer_stopwatch:
with Stopwatch(name='inner') as inner_stopwatch:
for i in range(5):
with inner_stopwatch.lap():
time.sleep(i / 10)
print(inner_stopwatch.elapsed) # 1.0013675531372428
print(inner_stopwatch.laps) # [3.256136551499367e-05, 0.10015189787372947, 0.20030939625576138, 0.3003752687945962, 0.40049842884764075]
print(outer_stopwatch.report()) # [Stopwatch#outer] total=1.0015s
print(inner_stopwatch.report()) # [Stopwatch#inner] total=1.0014s, mean=0.2003s, min=0.0000s, median=0.2003s, max=0.4005s, dev=0.1416s
@profile(name='wait_for')
def wait_for(ts):
if not ts:
return
time.sleep(ts[0])
wait_for(ts[1:])
wait_for([0.1, 0.2, 0.3, 0.4, 0.5])
# [profile#wait_for] hits=1, mean=0.0000s, min=0.0000s, median=0.0000s, max=0.0000s, dev=0.0000s
# [profile#wait_for] hits=2, mean=0.2507s, min=0.0000s, median=0.2507s, max=0.5013s, dev=0.2506s
# [profile#wait_for] hits=3, mean=0.4679s, min=0.0000s, median=0.5013s, max=0.9025s, dev=0.3692s
# [profile#wait_for] hits=4, mean=0.6519s, min=0.0000s, median=0.7019s, max=1.2037s, dev=0.4514s
# [profile#wait_for] hits=5, mean=0.8025s, min=0.0000s, median=0.9025s, max=1.4048s, dev=0.5037s
# [profile#wait_for] hits=6, mean=0.9197s, min=0.0000s, median=1.0531s, max=1.5060s, dev=0.5293s
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
python-stopwatch-1.0.0.tar.gz
(3.3 kB
view hashes)
Built Distribution
Close
Hashes for python_stopwatch-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a46e0a72e570d2da05aef47df0d0332ed7242b729e9a9b91f7f6765f076161b |
|
MD5 | 1745de580c7202c0ec5259f3149ecec3 |
|
BLAKE2b-256 | 970149c2463a6635cd23f947a6048c939215f24315dfed3a8360c90962794373 |