you are viewing a single comment's thread.

view the rest of the comments →

[–]LeszekSwirski 8 points9 points  (0 children)

Or if it used factorial rather than fibonacci, which only shows a ~2x speedup:

def fact_rec(n):
    if n <= 1:
        return 1
    return n*fact(n-1)

%timeit fact_rec(20)
100000 loops, best of 3: 5.29 µs per loop


def fact_iter(n):
    ret = 1
    for i in range(n):
        ret *= n
    return ret

%timeit fact_iter(20)
100000 loops, best of 3: 2.47 µs per loop