Is python really slow?

Lulu of the Lotus-Eaters mertz at gnosis.cx
Wed May 22 13:35:53 EDT 2002


|Kragen Sitaker wrote:
|> 1. Python is really slow, because it's highly dynamic and because it's
|> interpreted.  This is true of Perl, too.  Primitive operations in both
|> languages are roughly 100 to 1000 times slower than in languages
|> compiled to machine code.

Peter Hansen <peter at engcorp.com> wrote previously:
|From no doubt a very different background, my experience has shown the
|number to be more in the range of 10 to 100 times slower, averaging
|about 30 times.  In fact, the 100 times was usually with non-Pythonic
|code, written with fairly heavy for-loops and lots of strings being
|concatenated inefficiently.

I think Kragen and Peter are probably both right in their estimates,
because they are talking about slightly different things.  If you just
compare a raw loop, for example, C is easily 1000 times faster, e.g.

    for ln in lines:  pass                        vs.
    for (i=0; lines[i][0]; i++) {ln = lines[i];}

But once you *do* something inside a loop, Python typically makes use of
some higher-level facility that is implemented in a more-or-less optimal
way, e.g.

    import re
    new = []
    for ln in lines:
        new.append(re.sub('[Ff][Oo][Oo]','Bar',ln))

Doing that in C takes a lot more lines... but moreover, the lines you
actually write won't be any better than what re.sub() does internally.

Yours, Lulu...

--
 mertz@   _/_/_/_/_/_/_/ THIS MESSAGE WAS BROUGHT TO YOU BY:_/_/_/_/ v i
gnosis  _/_/                    Postmodern Enterprises         _/_/  s r
.cx    _/_/  MAKERS OF CHAOS....                              _/_/   i u
      _/_/_/_/_/ LOOK FOR IT IN A NEIGHBORHOOD NEAR YOU_/_/_/_/_/    g s






More information about the Python-list mailing list