WHY is python slow?

John Roth johnroth at ameritech.net
Thu Jun 7 09:12:38 EDT 2001


"Steven Haryanto" <steven at haryan.to> wrote in message
news:mailman.991900751.7603.python-list at python.org...
> Although it is generally accepted that Python is slower than
> Java/Perl/Ruby, a layman like me would be curious to know why
> exactly this is so. In other words, why is the implementation
> of a language like Ruby (which is on par with Python in terms
> of 'everything is an object', strong reflection, dynamic
> nature).
>
> My first guess would be the ubiquitous use of dictionaries?
>
> Steve
> http://stevne.haryan.to/

I think this requires a slightly more thoughtful answer than the ones that
have been given so far (at least, the ones that have propagated to my
news server.)

1. Java is a strongly typed language that has been compared favorably
to C++. As such, it has inherent advantages with respect to runtime storage
allocation (always the big, and I mean really big, time consumer in any
language implementation) and code generation.

In addition, as one of the other responders said, a lot of money got
thrown at it, and is still being thrown at it, to improve performance.

2. As far as Perl goes, Perl's code generation model is very different.
Python generates byte codes, which, as you would expect, are single
bytes. Perl generates relatively large structures where the execution
sequence is explicitly handled by pointers from one code block to the
next (somewhat similar to the very ancient IBM 650.)

There are other very significant differences. Perl's function call
syntax and semantics are very primative: there is no conception of
either default or keyword arguements, so it has inherently less
overhead in function calls.

Whether this does anything favorable in terms of execution time is
beyond me. Technically, it should as it reduced interpreter overhead -
there are fewer iterations of the interpreter main loop for a given
amount of functionality.

3. As far as Ruby goes, I'm going to have to confess total ignorance
about how it handles things.

4. Any statement I made (at this point) about the major performance
bottleneck in Python would be a guess. However, if I were to guess,
I would look at storage allocation overall. Dynamic storage allocation
and garbage collection have always been the Achilles heel of any
object oriented implementation - that's why C++ allows you to specify
your own storage allocator.

Hopefully, this gives you something to chew on.

John H. Roth Jr.
>
>





More information about the Python-list mailing list