Profiling, recursive func slower than imperative, normal?

Jean-Paul Calderone exarkun at divmod.com
Wed Apr 16 16:27:40 EDT 2008


On Wed, 16 Apr 2008 13:18:22 -0700 (PDT), skanemupp at yahoo.se wrote:
>the 0.409 vs 0.095 is the total times right?
>so the imperative function is >4 times faster than the recursive.
>or what does tottime stand for?
>
>is this always the case that the recursive function is slower?
>the gain is less code?
>
>are some functions only implementable recursively?
>

Function calls (recursive or otherwise) are more expensive than
for loops, so the version that replaces recursion with a loop is
faster.

Any function can be implemented without recursion, although it isn't
always easy or fun.

Jean-Paul



More information about the Python-list mailing list