-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtictoc.py
More file actions
24 lines (19 loc) · 707 Bytes
/
tictoc.py
File metadata and controls
24 lines (19 loc) · 707 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import time
def TicTocGenerator():
# Function that returns time differences
ti = 0 # initial time
tf = time.time() # final time
while True:
ti = tf
tf = time.time()
yield (tf-ti) #Returns the time difference
TicToc = TicTocGenerator() #create an instance of the TicTocGenerator
# Main function through which we define both tic() and toc()
def toc(tempBool = True):
# Prints the time difference yielded by instance of TicTocGenerator()-TicToc
tempTimeInterval = next(TicToc)
if tempBool:
print("Elapsed time: %f seconds.\n" %tempTimeInterval)
def tic():
# Records a time in TicToc, marks the beginning of a time interval
toc(False)