Automatic commit performed through alias...
This commit is contained in:
@@ -8,27 +8,20 @@
|
|||||||
#
|
#
|
||||||
# Find the sum of all the multiples of 3 or 5 below 1000.
|
# Find the sum of all the multiples of 3 or 5 below 1000.
|
||||||
|
|
||||||
import functools
|
|
||||||
import time
|
|
||||||
|
|
||||||
def timer(f):
|
def f_timer(passed_f):
|
||||||
""" Decorator function to calculate compute time of passed function. """
|
|
||||||
|
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
|
||||||
|
|
||||||
@functools.wraps(f)
|
return inner_f
|
||||||
def wrapper_timer(*args,**kwargs):
|
|
||||||
|
|
||||||
start_time = time.perf_counter()
|
|
||||||
|
|
||||||
f(*args, **kwargs)
|
|
||||||
|
|
||||||
end_time = time.perf_counter()
|
|
||||||
run_time = end_time - start_time
|
|
||||||
|
|
||||||
print("Finished {func.__name__!r} in {run_time:.4f} seconds...")
|
|
||||||
|
|
||||||
return f
|
|
||||||
|
|
||||||
return wrapper_timer
|
|
||||||
|
|
||||||
def check_divisibility(num, dict_multiples: dict) -> bool:
|
def check_divisibility(num, dict_multiples: dict) -> bool:
|
||||||
|
|
||||||
@@ -41,7 +34,7 @@ def check_divisibility(num, dict_multiples: dict) -> bool:
|
|||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@timer
|
@f_timer
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
multiples = {3,5}
|
multiples = {3,5}
|
||||||
|
|||||||
Reference in New Issue
Block a user