A timing package that mimics MATLAB's tic and toc functionality
Project description
MATLAB Tic Toc
A Python module to make timing in python easier by mimicing MATLAB's tic
and toc
functions.
tic
starts a timer by recording the current time, and toc
uses the start time to find the elapsed time.
The included func_timer
decorator uses tic
and toc
to give the elapsed time of the wrapped function.
Usage
from tictoc import tic, toc
tic() # starts the global timer
timer = tic() # assigns an instance of the Timer class to the timer var without affecting the global timer
toc() # Prints elapsed time from tic() call
toc(timer) # Prints elapsed time for the timer given
time = toc(timer) # Assigns elapsed time to a variable
timer.reset() # Resets the timer var start time
tic() # Restarts the global timer
Examples
from time import sleep
from tictoc import tic, toc, func_timer
tic() # starts global timer
sleep(1)
toc()
sleep(2)
toc()
Elapsed time is 1.00547 seconds.
Elapsed time is 3.00886 seconds.
timer = tic()
sleep(1)
print(f'Timer Assigned to var: {toc(timer)}')
print(f'Global Timer: {toc()}')
Timer Assigned to var: 1.0057699
Global Timer: 4.013537
@func_timer
def func():
sleep(2)
func()
Elapsed time for function func is 2.00556969 seconds.
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
Built Distribution
File details
Details for the file matlab-tictoc-1.1.0.tar.gz
.
File metadata
- Download URL: matlab-tictoc-1.1.0.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6ee1c776dc70a73a08a127b66eefd024e3ef95678dcf5d70dbb2a56ed400f06 |
|
MD5 | ca813f13f0cd5cac6c62381317684501 |
|
BLAKE2b-256 | fb1c44ddb3d3b78a2315df47bcc79e611a50b39ce2dc0d5a4d7753ff1ee3cda1 |
File details
Details for the file matlab_tictoc-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: matlab_tictoc-1.1.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 719344517cd647205d74d684fd5d1d895ec0af06f05ba946151a7f85317603e9 |
|
MD5 | 8fbb1390aef88682773e18fce40a1381 |
|
BLAKE2b-256 | 839623339dcd567ba8176411d9b74e11627fc69416eb06b3af94dc84815e405a |