Skip to content

Instantly share code, notes, and snippets.

@lucassmagal
Created June 16, 2012 17:53
Show Gist options
  • Save lucassmagal/2942086 to your computer and use it in GitHub Desktop.
Save lucassmagal/2942086 to your computer and use it in GitHub Desktop.
Fibonacci with timeit module
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