import time def lucas(n): """Calculates recursively the n-th lucas number. The function assumes that its input is a non-negative integer, otherwise it will run indefinitely long.""" if n==0: return 2 if n==1: return 1 return lucas(n-1)+lucas(n-2) def timeit(func): for n in range(100): start = time.time() value = func(n) duration = time.time()-start print(n, value, duration) if duration > 0.5: break