Python 2 times slower than Perl

Johann Hibschman johann at physics.berkeley.edu
Wed Jul 18 12:26:27 EDT 2001


Peter Hansen writes:

> In practice, we've found Python to be somewhere between
> 30 and 100 times slower than C, clearly depending on the
> algorithm and without really much effort to optimize.
> (That is, our Python code could probably withstand
> some significant optimization, if we cared to.)

I've been playing with ocaml, so I thought I'd try the results on my
computer, a Mac PowerBook G3/400.  Things don't look so good for the
G3/400 processor though, at least on OS X.

I get:

cc -O2       0.28
cc           0.62
ocamlopt     1.26   (compiled)
ocaml        9.42   (interpreted)
perl        28.9
python      66.8

Hm.  I'm beginning to wonder if I compiled python with -O2 or not.
Plus, I'm becoming more and more fond of ocaml.

The python function I used was the basic

def test ():
    i = 2.5
    j = 2.5
    while i < 1e7:
        j = 2.5 * 2.5
        i = i + 1.0
    print "%f %f\n" % (i, j)

if __name__ == '__main__':
    test ()

--Johann



More information about the Python-list mailing list