Created
April 28, 2017 08:38
-
-
Save moskomule/5554b46d8905451d0b6ce1e1059848e9 to your computer and use it in GitHub Desktop.
usage of functools.lru_cache and timeit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import timeit | |
import functools | |
@functools.lru_cache(maxsize=None) | |
def fib(x): | |
if x < 2: | |
return x | |
return fib(x-1) + fib(x-2) | |
print(timeit.timeit('fib(100)', setup="from __main__ import fib")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment