def cumulative_elapsed_time_example(): print( "[cumulative_elapsed_time_example] use python logging module with different log level" ) timer = Stopwatch("Waiting") with timer: sleep(1) sleep(1) with timer: sleep(1) timer.log_elapsed_time( prefix="timer.log_elapsed_time(): ") # 0:00:01.... print("timer.get_elapsed_time():", timer.get_elapsed_time()) # 0:00:01.... print("timer.split_elapsed_time:", timer.split_elapsed_time) # [datetime.timedelta(seconds=1), datetime.timedelta(seconds=1)] print("timer.get_cumulative_elapsed_time():", timer.get_cumulative_elapsed_time())
def basic_example(): print("[basic_example]") timer = Stopwatch() sleep(0.1) timer.log_elapsed_time() # 0:00:00 timer.start() sleep(0.1) timer.log_elapsed_time() # 0:00:00.1 sleep(0.1) timer.pause() timer.log_elapsed_time() # 0:00:00.2 sleep(0.1) timer.log_elapsed_time() # 0:00:00.2 timer.split() # 0:00:00.2 timer.log_elapsed_time() # 0:00:00 print("timer.get_cumulative_elapsed_time():", timer.get_cumulative_elapsed_time()) # 0:00:00.2 sleep(0.1) timer.start() sleep(0.1) timer.log_elapsed_time() # 0:00:00.1 print("timer.get_cumulative_elapsed_time():", timer.get_cumulative_elapsed_time()) # 0:00:00.3 timer.split() # 0:00:00.1 sleep(0.1) timer.pause() timer.split() # 0:00:00.1 print("timer.get_cumulative_elapsed_time():", timer.get_cumulative_elapsed_time()) # 0:00:00.4 print("timer.split_elapsed_time:", [str(delta) for delta in timer.split_elapsed_time]) # [0:00:00.2, 0:00:00.1, 0:00:00.1] timer.reset() timer.log_elapsed_time() # 0:00:00 print("timer.get_cumulative_elapsed_time():", timer.get_cumulative_elapsed_time()) # 0:00:00 print("timer.split_elapsed_time:", timer.split_elapsed_time) # [] sleep(0.1) timer.start() sleep(0.1) timer.log_elapsed_time() # 0:00:00.1