From b9f031cc5cf7535599fa7b2008c5255ecb6cb73e Mon Sep 17 00:00:00 2001 From: Shaun Setlock Date: Tue, 14 Apr 2020 21:01:53 -0400 Subject: [PATCH] Automatic commit performed through alias... --- problems/001_problem.py | 17 ++--------------- problems/__init__.py | 0 problems/decorators.py | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+), 15 deletions(-) create mode 100644 problems/__init__.py create mode 100644 problems/decorators.py diff --git a/problems/001_problem.py b/problems/001_problem.py index d77f3b7..ea7a4c7 100644 --- a/problems/001_problem.py +++ b/problems/001_problem.py @@ -8,20 +8,7 @@ # # Find the sum of all the multiples of 3 or 5 below 1000. - -def f_timer(passed_f): - - def inner_f(*args, **kwargs): - - import time - t1 = time.time() - value = passed_f(*args, **kwargs) - t2 = time.time() - t3 = t2 - t1 - print("The function {} ran for {:4f} seconds... ".format(passed_f.__name__,t3)) - return value - - return inner_f +import decorators def check_divisibility(num, dict_multiples: dict) -> bool: @@ -34,7 +21,7 @@ def check_divisibility(num, dict_multiples: dict) -> bool: else: return False -@f_timer +@decorators.function_timer def main(): multiples = {3,5} diff --git a/problems/__init__.py b/problems/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/problems/decorators.py b/problems/decorators.py new file mode 100644 index 0000000..4636837 --- /dev/null +++ b/problems/decorators.py @@ -0,0 +1,20 @@ +""" + +Collection of decorators that could be helpful while solving problems. + +""" + +# Function decorator which calculates the time required to execute a function. +def function_timer(passed_f): + + def inner_f(*args, **kwargs): + + import time + t1 = time.time() + value = passed_f(*args, **kwargs) + t2 = time.time() + t3 = t2 - t1 + print("The function {} ran for {:4f} seconds... ".format(passed_f.__name__,t3)) + return value + + return inner_f