24 lines
532 B
Python
24 lines
532 B
Python
|
import time
|
||
|
|
||
|
def bad_timeit(f):
|
||
|
def timeitwrapper(*args, **kwargs):
|
||
|
start = time.time()
|
||
|
result = f(*args, **kwargs)
|
||
|
stop = time.time()
|
||
|
elapsed = stop - start
|
||
|
print("the function", f.__name__, "has been executed in", elapsed, "s.")
|
||
|
return result
|
||
|
return timeitwrapper
|
||
|
|
||
|
def _recursive_fibonacci(n):
|
||
|
if n in (0, 1):
|
||
|
return 1
|
||
|
return _recursive_fibonacci(n - 1) + _recursive_fibonacci(n - 2)
|
||
|
|
||
|
@bad_timeit
|
||
|
def recursive_fibonacci(n):
|
||
|
return _recursive_fibonacci(n)
|
||
|
|
||
|
if( __name__ == "__main__"):
|
||
|
recursive_fibonacci(43)
|