|
|
|
|
@ -16,6 +16,9 @@ use_ANSI_Colors = True |
|
|
|
|
|
|
|
|
|
# ANSI escape codes for colors |
|
|
|
|
WHITE = "\033[97m" |
|
|
|
|
BRIGHT_GREEN = "\033[92m" |
|
|
|
|
BRIGHT_YELLOW = "\033[93m" |
|
|
|
|
BRIGHT_RED = "\033[91m" |
|
|
|
|
RESET = "\033[0m" |
|
|
|
|
|
|
|
|
|
start = time.perf_counter() |
|
|
|
|
@ -29,12 +32,25 @@ def exit_handler(signum, frame): |
|
|
|
|
# CTRL+C will Exit NOW!!! |
|
|
|
|
signal.signal(signal.SIGINT, exit_handler) |
|
|
|
|
|
|
|
|
|
def get_color_for_timer(total): |
|
|
|
|
match total: |
|
|
|
|
case x if x < 1: # 0.x |
|
|
|
|
return BRIGHT_GREEN |
|
|
|
|
case x if 1 <= x <= 7: # Matches 1 to 7 |
|
|
|
|
return WHITE |
|
|
|
|
case x if x >= 10: |
|
|
|
|
return BRIGHT_RED |
|
|
|
|
case _: |
|
|
|
|
return BRIGHT_YELLOW #8-9 |
|
|
|
|
|
|
|
|
|
def exit_timer(level): |
|
|
|
|
end = time.perf_counter() |
|
|
|
|
total_time = end - start |
|
|
|
|
if use_ANSI_Colors == True: |
|
|
|
|
print(f"{WHITE}⏱ Execution took {end - start:.4f} seconds{RESET}") |
|
|
|
|
use_color = get_color_for_timer(total_time) |
|
|
|
|
print(f"{use_color}⏱ Execution took {total_time:.4f} seconds{RESET}") |
|
|
|
|
else: |
|
|
|
|
print(f"⏱ Execution took {end - start:.4f} seconds") |
|
|
|
|
print(f"⏱ Execution took {total_time:.4f} seconds") |
|
|
|
|
|
|
|
|
|
exit(level) |
|
|
|
|
|
|
|
|
|
@ -68,7 +84,8 @@ class Timer: |
|
|
|
|
def print_result(self): |
|
|
|
|
elapsed = self.elapsed() |
|
|
|
|
if use_ANSI_Colors == True: |
|
|
|
|
print(f"{self.name}: {WHITE}⏱ {elapsed:.6f} seconds{RESET}") |
|
|
|
|
use_color = get_color_for_timer(elapsed) |
|
|
|
|
print(f"{self.name}: {use_color}⏱ {elapsed:.6f} seconds{RESET}") |
|
|
|
|
else: |
|
|
|
|
print(f"{self.name}: ⏱ {elapsed:.6f} seconds") |
|
|
|
|
|
|
|
|
|
|