Created
November 18, 2014 23:14
-
-
Save xhacker/fbf3d92d7b1fad9ddc09 to your computer and use it in GitHub Desktop.
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
from timeit import timeit | |
setup = """ | |
results = [0 for _ in xrange(100)] | |
results[1] = 1 | |
results[2] = 1 | |
def fib(n): | |
if results[n]: | |
return results[n] | |
results[n] = fib(n - 1) + fib(n - 2) | |
return results[n] | |
""" | |
timeit(stmt='fib(35)', setup=setup, number=1000000) | |
setup = """ | |
def fib(n): | |
a, b = 1, 1 | |
for _ in xrange(n - 1): | |
a, b = b, a + b | |
return a | |
""" | |
timeit(stmt='fib(35)', setup=setup, number=1000000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment