Time the execution of Python code using syntax similar to MATLAB's tic and toc functions.
Project description
py-tictoc-timer
Time the execution of Python code using syntax similar to MATLAB's tic and toc functions.
Installation
Using pip
:
pip install py-tictoc-timer
Using pipenv
:
pipenv install py-tictoc-timer
Using poetry
:
- In your
pyproject.toml
file, add:[tool.poetry.dependencies] py-tictoc-timer = "*"
- Then in the terminal, run:
poetry install
Using conda
conda install py-tictoc-timer
Usage
Basic usage:
>>> from tictoc import TicToc
>>> from time import sleep
>>> tt = TicToc()
>>> tt.tic()
>>> sleep(1.1)
>>> tt.toc()
Elapsed time: 1secs
Within context manager:
>>> from tictoc import TicToc
>>> from time import sleep
>>> with TicToc():
... sleep(1.1)
Elapsed time: 1secs
Within context manager using custom messages:
>>> from tictoc import TicToc
>>> from time import sleep
>>> with TicToc(begin_message="start", end_message="end"):
... sleep(1.1)
start
end: 1secs
Custom message:
>>> from tictoc import TicToc
>>> from time import sleep
>>> with TicToc("Total Time"):
... sleep(1.1)
Total time: 1secs
With restart during .tic()
:
>>> from tictoc import TicToc
>>> from time import sleep
>>> tt = TicToc()
>>> tt.tic(restart=True)
>>> sleep(1.1)
>>> toc()
Elapsed time: 1secs
>>> toc()
Elapsed time: 1secs
With restart during .toc()
:
>>> from tictoc import TicToc
>>> from time import sleep
>>> tt = TicToc()
>>> tt.tic()
>>> sleep(1.1)
>>> tt.toc(restart=True)
Elapsed time: 1secs
>>> tt.toc()
Elapsed time: 1secs
With restart using .rtoc()
:
>>> from tictoc import TicToc
>>> from time import sleep
>>> tt = TicToc()
>>> tt.tic()
>>> sleep(1.1)
>>> tt.rtoc()
Elapsed time: 1secs
>>> tt.toc()
Elapsed time: 1secs
With time returned:
>>> from tictoc import TicToc
>>> from time import sleep
>>> tt = TicToc()
>>> tt.tic()
>>> sleep(1.1)
>>> value = tt.toc_value()
>>> print(round(value, 1))
1.1
Contribution
All contributions are welcome!
Build & Test
Run Black
python -m pipenv run python -m black --safe py_tictoc_timer tests
Run PyTests:
python -m pipenv run python -m pytest --verbose --cov=py_tictoc_timer --cov-report=term --cov-report=html:cov-report/html --cov-report=xml:cov-report/xml/cov-report.xml
Run MyPy Tests:
pipenv run mypy py_tictoc_timer --ignore-missing-imports --pretty --install-types --non-interactive
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
py-tictoc-timer-0.1.13.tar.gz
(5.4 kB
view hashes)
Built Distribution
Close
Hashes for py_tictoc_timer-0.1.13-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65c2c6acf701531539c49de4fc0f434ade97b2694490e142758df4b951d90314 |
|
MD5 | bacb076fdfc15d45e0029d2ed59ed0ca |
|
BLAKE2b-256 | b25865f546afbbf1cfaa91849d88848736cbc471f698392e2290c0c14242bbf6 |