[code.view]

[top] / python / PyMOTW / profile / profile_fibonacci_raw.py

     #!/usr/bin/env python
     # encoding: utf-8
     #
     # Copyright (c) 2008 Doug Hellmann All rights reserved.
     #
     """
     """
     
     __version__ = "$Id$"
     #end_pymotw_header
     
     import profile
     
     def fib(n):
         # from http://en.literateprograms.org/Fibonacci_numbers_(Python)
         if n == 0:
             return 0
         elif n == 1:
             return 1
         else:
             return fib(n-1) + fib(n-2)
     
     def fib_seq(n):
         seq = [ ]
         if n > 0:
             seq.extend(fib_seq(n-1))
         seq.append(fib(n))
         return seq
     
     print 'RAW'
     print '=' * 80
     profile.run('print fib_seq(20); print')
     

[top] / python / PyMOTW / profile / profile_fibonacci_raw.py

contact | logmethods.com