Created
June 16, 2012 17:53
-
-
Save lucassmagal/2942086 to your computer and use it in GitHub Desktop.
Fibonacci with timeit module
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 | |
SETUP = """ | |
def fib(n, p0=0, p1=1): | |
if n == 0: | |
return p1 | |
return fib(n-1, p1, p0+p1) | |
""" | |
t = timeit.Timer(stmt="fib(150)", setup=SETUP) | |
# It will run setup code once, and | |
# then will return the time it takes to | |
# run 'stmt' a number of times, | |
# measuring in seconds | |
print t.timeit(number=100) | |
# result: 0.00840497016907 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment