diff --git a/src/Python/utils.py b/src/Python/utils.py index 6d70861..a06df8a 100644 --- a/src/Python/utils.py +++ b/src/Python/utils.py @@ -5,19 +5,31 @@ from functools import wraps def timeit(name): def profile(original): import time + @wraps(original) def wrapper(*args, **kwargs): t0 = time.perf_counter() result = original(*args, **kwargs) t1 = time.perf_counter() - print(f"Time to evaluate problem {int(name[7:]):003d}: {(t1 - t0)*1000:.3f} ms\n") + if (t1 - t0) > 1: + print( + f"Time to evaluate problem {int(name[7:]):003d}: " + f"{(t1 - t0):.3f} s\n" + ) + else: + print( + f"Time to evaluate problem {int(name[7:]):003d}: " + f"{(t1 - t0)*1000:.3f} ms\n" + ) return result + return wrapper + return profile def is_prime(n): - if n <2: + if n < 2: return False for i in range(2, int(math.sqrt(n)) + 1): if n % i == 0: @@ -45,4 +57,4 @@ def list_primes(n): def is_palindrome(num): - return str(num) == str(num)[::-1] \ No newline at end of file + return str(num) == str(num)[::-1]