Python/Scripting language performance

Skip Montanaro skip at pobox.com
Thu May 30 22:24:30 EDT 2002


    Curtis> I'm looking for an explicit explination of why Scripting
    Curtis> languages, specificaly Python, are slow compared to compiled
    Curtis> languages.

Languages like Python and Perl (I think you do both a disservice by calling
them "scripting" languages) are compiled to fairly high-level virtual
machines.  The bytecode is then interpreted at run-time.  Interpreting
bytecode is much less efficient than executing native machine code on real
hardware.  Compiling dynamically types languages to efficient machine code
is difficult.  C, C++ and Java are easier to compile to fairly efficient
machine code because they are statically typed.  Dynamic typing means you
can't know ahead of time that (for example) the variable named "x" will
always be an int.  C knows that "int x;" means that it can generate a very
efficient sequence of machine instructions to perform the expression "x +
5".  The Python compiler doesn't know what "x + 5" means because it doesn't
know, a priori, what the type of x is and thus what the semantics of the
addition operator are going to be.

That's not the end of the story, however.  Take a look at the Psyco project
for a system that provides some tantalizing performance improvements:

    http://sourceforge.net/projects/psyco

I believe the Parrot project is also working on a more efficient virtual
machine for Perl (and eventually other languages).

-- 
Skip Montanaro (skip at pobox.com - http://www.mojam.com/)
Boycott Netflix - they spam - http://www.musi-cal.com/~skip/netflix.html






More information about the Python-list mailing list