xxxxxxxxxx
# Install TimeV2
`pip install timev2`
from TimeV2 import time2
# Record the time it takes to wait 5 seconds
time2.stopwatch_start()
time2.wait(5)
timeRecorded = time2.stopwatch_stop()
print(timeRecorded)
xxxxxxxxxx
import time
time_to_stop = 10 #seconds
for x in range(1, time_to_stop+1):
print(x)
time.sleep(1)
xxxxxxxxxx
import time
def stopwatch(info):
def _decorator(func):
def wrapper(*args, **kwargs):
t1 = time.time()
output = func(*args, **kwargs)
t2 = time.time()
print('%s: %.3fms' % (info,(t2-t1)*1000) )
return output
return wrapper
return _decorator
@stopwatch('sample code')
def test():
x = 0
for i in range(100000):
x += i
test()
xxxxxxxxxx
import time
now = time.time()
future = now + 10
while time.time() < future:
# do stuff
pass