33 lines
620 B
Python
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
|
|
"""
|