Python vs. Perl, which is better to learn?

John La Rooy larooy at xtar.co.nz
Thu May 23 06:55:00 EDT 2002


This way is 10 times faster than C with plain recursive calls.

def recfib(n,fibcache={}):
    if n not in fibcache:
        fibcache[n] = n <= 2 or recfib(n-1) + recfib(n-2)
    return fibcache[n]

print recfib(33)

John

On 23 May 2002 03:10:17 -0400
Kragen Sitaker <kragen at pobox.com> wrote:

> "Terry Reedy" <tjreedy at udel.edu> writes:
> > Newcomer Troll:  Ha ha.  I just ran a comparative test and Python is
> > WAAAY slow.
> > 
> > Pythoneer:  Can you give us some details?
> > 
> > NT:  Yeah.  My turbo-lang version took 1/100 second and Python took a
> > *whole* second -- 100 times slower.
> 
> For an example, where Python came out to be 140 times slower than C in
> a simple test, see
> http://lists.canonical.org/pipermail/kragen-tol/2000-April/000571.html
> --- fib(33), using the straightforward exponential-time algorithm, was
> the microbenchmark.
> 
> For lots more examples, see the Great Computer Language Shootout, at
> http://www.bagley.org/~doug/shootout --- the above performance is
> pretty average, although Python fares considerably better in the
> "real" problems (each program does the same thing) than in the
> "artifical" problems (each program is written the same way).
> 



More information about the Python-list mailing list