Fast, simple and accurate Python timing. Written in Rust.
|
||
---|---|---|
.docs | ||
.github/workflows | ||
src | ||
tests | ||
.gitignore | ||
Cargo.lock | ||
Cargo.toml | ||
pyproject.toml | ||
README.md | ||
requirements.txt | ||
run.py |
Fast, simple and accurate Python timing. Written in Rust.
Installation
Install with pip.
$ python -m pip install tictoc
Usage
Import and initialise. The module must be initialised to be used!
import tictoc
t = tictoc.init()
Begin timing with tic()
, and stop with toc()
.
t.tic()
# some code
t.toc()
When toc
is called, the results are saved. They can be accessed with the following syntax:
t.results.{unit}
The available units are:
t.results.nanos # u128
t.results.micros # u128
t.results.millis # u128
t.results.seconds # f64
Full example
import time
import tictoc
t = tictoc.init()
t.tic() # start timing
time.sleep(3) # sleep for 3 seconds
t.toc() # stop timing
print(t.results.seconds)
# >>> 3.000457715