Skip to content

Instantly share code, notes, and snippets.

@moskomule
Created April 28, 2017 08:38
Show Gist options
  • Save moskomule/5554b46d8905451d0b6ce1e1059848e9 to your computer and use it in GitHub Desktop.
Save moskomule/5554b46d8905451d0b6ce1e1059848e9 to your computer and use it in GitHub Desktop.
usage of functools.lru_cache and timeit
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