By not cloning code for recursion directly into the processing buffer and by not copying as many strings and by not doing string->int conversions all the time, it's significantly faster. Specifically, it's about 5.5x slower than Python.
18 lines
226 B
Python
18 lines
226 B
Python
def fib( a ):
|
|
if a == 0:
|
|
return 0
|
|
elif a == 1:
|
|
return 1
|
|
else:
|
|
return fib( a - 1 ) + fib( a - 2 )
|
|
|
|
def do_fibs( cnt ):
|
|
if cnt > 0:
|
|
do_fibs( cnt - 1 )
|
|
print( fib( cnt ) )
|
|
else:
|
|
print( fib( 0 ) )
|
|
|
|
|
|
do_fibs( 38 )
|