why is python slow?

Tim Hammerquist tim at vegeta.ath.cx
Fri Mar 8 01:45:50 EST 2002


les ander <les_ander at yahoo.com> graced us by uttering:
> i am just curious as to why different programming languages have
> different speed.
[ snip ]
> why is a perl program faster than similar python program?

Oh dear. You said the P-word. The four-letter P-word. Nothing
stigmatizes a comp.lang.python thread faster than bringing up Perl.
<wink>

However, your statement is far too subjective. Differences in
execution speed between any two languages often depend much more on
the knowledge, wisdom, and experience of the programmer than on which
language is used.

OTOH, Perl is optimized for certain things, and Python is optimized
for others.  Finally, words like "faster" and "similar" are far too
subjective to get an accurate answer. If, however, you were to ask:

    Why does a hypothetical benchmark show shorter execution time for

        #/usr/bin/perl -w
        print while <>;

    than for the roughly functionally equivalent Python code

        #!/usr/bin/python
        import fileinput
        for line in fileinput.input():
            print line,

    ???
    TIA,
    J. R. Hacker

...you might find out that this is one particular area where Perl has
been specifically optimized.

> For example
> when java came out it use to be pretty slow, but now it is pretty fast. How
> was this speed-up acheived and why is it not possible to have such a speed up
> for python?

How this speedup was achieved is a problem I leave for Sun. However,
the _reason_ this speedup was sought was because Java had gotten such
a bad rep for being slow in the past. And so, industry competition
once again achieves improvement through pressure. BTW, this is the
same reason Perl implemented a (crufty) object system: user demand.

> P.S. I am just trying to understand and do not intend to put down
> python by any means.

Understood.  But the trick, as always, is not finding the right place
to get an answer, but rather, knowing _which_ question to ask in the
first place. <wink>

HTH
Tim Hammerquist
-- 
You can lead a bigot to water, but if you don't
tie him up, you can't make him drown.
    -- The Psychodots



More information about the Python-list mailing list