Files
Learn-Python-Programming-Th…/ch11/custom_timestamp.py
T
adii1823 3cebc2fe91 ch11
2021-10-28 17:40:37 +05:30

33 lines
620 B
Python

# custom_timestamp.py
from time import sleep
def debug(*msg, timestamp=[None]):
print(*msg)
from time import time # local import
if timestamp[0] is None:
timestamp[0] = time() #1
else:
now = time()
print(
' Time elapsed: {:.3f}s'.format(now - timestamp[0])
)
timestamp[0] = now #2
debug('Entering nasty piece of code...')
sleep(.3)
debug('First step done.')
sleep(.5)
debug('Second step done.')
"""
$ python custom_timestamp.py
Entering nasty piece of code...
First step done.
Time elapsed: 0.300s
Second step done.
Time elapsed: 0.500s
"""