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()# 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)