Install with pip.
$ python -m pip install tictoc
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
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