TicTocTimer
A very simple and easy to use implementation of timer object for python code, based on the tic/toc matlab syntax.
You can also find it on PyPi @ https://pypi.org/project/TicTocTimer
Using the common timer
Using the global
name label,
import time
from tic_toc_timer import tic, toc
tic()
time.sleep(10)
print(f"The total time elasped is {toc()}")
Using a custom label(s),
import time
from tic_toc_timer import tic, toc
tic("first")
time.sleep(10)
tic("second")
time.sleep(1)
first_elapsed = toc("first") # expected ~ 11 secs
second_elapsed = toc("second") # expected ~ 1 sec
Using a local timer
import time
from tic_toc_timer import TicTocTimer
timer = TicTocTimer()
timer.tic("first")
time.sleep(10)
timer.tic("second")
time.sleep(1)
first_elapsed = timer.toc("first") # expected ~ 11 secs
second_elapsed = timer.toc("second") # expected ~ 1 sec
Install
pip install TicTocTimer
From the git repo directly
To install from master branch,
pip install git+https://github.com/LamaAni/TicTocTimer.git@master
To install from a release (tag)
pip install git+https://github.com/LamaAni/TicTocTimer.git@[tag]
Contribution
Feel free to ping me in issues or directly on LinkedIn to contribute.
Licence
Copyright ©
Zav Shotan
and other contributors.
It is free software, released under the MIT licence, and may be redistributed under the terms specified in LICENSE
.