Created
April 1, 2021 14:17
-
-
Save joeyv120/be33623f445bd1de570a1678a3546328 to your computer and use it in GitHub Desktop.
Tic Toc Timer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from time import time | |
class TicToc(): | |
''' | |
Represents a simple timer-like, or stopwatch object. | |
tic() starts the timer. | |
toc() returns time (seconds) since tic() was called. | |
''' | |
def __init__(self): | |
self.time_start = None | |
def tic(self): | |
self.time_start = time() | |
return self.time_start | |
def toc(self): | |
if self.time_start is None: # if you didn't call tic() yet | |
return 0 | |
time_elapsed = time() - self.time_start | |
return time_elapsed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment