update
This commit is contained in:
parent
64a8d556fc
commit
e623a03995
@ -1,19 +1,35 @@
|
||||
from time import time
|
||||
from datetime import datetime
|
||||
|
||||
start_time_of_timers = dict()
|
||||
from rich.console import Console
|
||||
|
||||
console = Console()
|
||||
|
||||
timers_started_ats = dict()
|
||||
|
||||
|
||||
def start_timer(name=1, print_=True):
|
||||
started_at = time()
|
||||
start_time_of_timers[name] = started_at
|
||||
if print_:
|
||||
print(f"{name} started at: {started_at}")
|
||||
def start_timer(name=1, do_print=True):
|
||||
started_at = datetime.now()
|
||||
timers_started_ats[name] = started_at
|
||||
if do_print:
|
||||
console.print(f"{name:<{len(str(name)) + 4}} ", end="")
|
||||
print(f"started at: {started_at.strftime('%H:%M:%S.%f')}")
|
||||
return name, started_at
|
||||
|
||||
|
||||
def stop_timer(name=1, print_=True):
|
||||
ended_at = time()
|
||||
took = round(ended_at - start_time_of_timers[name], 6)
|
||||
if print_:
|
||||
print(f"{name} ended at: {ended_at}\ttook: {took} second(s)")
|
||||
return name, round(ended_at - start_time_of_timers[name], 6)
|
||||
def stop_timer(name=1, do_print=True):
|
||||
ended_at = datetime.now()
|
||||
took = ended_at - timers_started_ats[name]
|
||||
if do_print:
|
||||
console.print(f"{name:<{len(str(name)) + 4}} ", end="")
|
||||
print(f"{'ended at:':>11} {ended_at.strftime('%H:%M:%S.%f')} ", end="")
|
||||
console.print(f"took: {took}")
|
||||
return name, ended_at, took
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from time import sleep
|
||||
|
||||
start_timer()
|
||||
sleep(1)
|
||||
stop_timer()
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user