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):
|
def start_timer(name=1, do_print=True):
|
||||||
started_at = time()
|
started_at = datetime.now()
|
||||||
start_time_of_timers[name] = started_at
|
timers_started_ats[name] = started_at
|
||||||
if print_:
|
if do_print:
|
||||||
print(f"{name} started at: {started_at}")
|
console.print(f"{name:<{len(str(name)) + 4}} ", end="")
|
||||||
|
print(f"started at: {started_at.strftime('%H:%M:%S.%f')}")
|
||||||
return name, started_at
|
return name, started_at
|
||||||
|
|
||||||
|
|
||||||
def stop_timer(name=1, print_=True):
|
def stop_timer(name=1, do_print=True):
|
||||||
ended_at = time()
|
ended_at = datetime.now()
|
||||||
took = round(ended_at - start_time_of_timers[name], 6)
|
took = ended_at - timers_started_ats[name]
|
||||||
if print_:
|
if do_print:
|
||||||
print(f"{name} ended at: {ended_at}\ttook: {took} second(s)")
|
console.print(f"{name:<{len(str(name)) + 4}} ", end="")
|
||||||
return name, round(ended_at - start_time_of_timers[name], 6)
|
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