Skip to content

Instantly share code, notes, and snippets.

@joeyv120
Created April 1, 2021 14:17
Show Gist options
  • Save joeyv120/be33623f445bd1de570a1678a3546328 to your computer and use it in GitHub Desktop.
Save joeyv120/be33623f445bd1de570a1678a3546328 to your computer and use it in GitHub Desktop.
Tic Toc Timer
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