why python is slower than java?

Alex Martelli aleaxit at yahoo.com
Tue Nov 9 23:14:06 CET 2004


Lonnie Princehouse <finite.automaton at gmail.com> wrote:

> > Java is interpreted just like Python is...
> 
> Java bytecodes are interpreted, but javac has the opportunity to do
> some optimizations when compiling source into bytecodes that
> fundamentally can't be done for Python because it's interpreted.  

This assertion is, simply, wrong.  The Python compiler has the
opportunity to perform plenty of optimizations, too.  If it only
performs a very few of them is most definitely _NOT_ "because it's
interpreted": Python is interpreted just as much as Java is.

> There's no equivalent of "exec" in Java.

...so on any function containing an 'exec', even the few key
optimizations the Python compiler does are turned off.  So what?
Doesn't mean they have to be turned off in normal, sane functions which
simply to NOT use 'exec'.

The fact that optimizations are turned off is one of many excellent
reasons to avoid USING Python's exec, btw.

>   Psyco makes a valiant
> attempt to do this sort of optimization (and does an excellent job!),
> but it's not hard to write perfectly legal Python code that makes
> Psyco explode.

I wouldn't be surprised if psyco had bugs: so did the first several
generations of Java JITs, even with a couple more orders of magnitude of
people slaving away on them than have worked on psyco.  That has nothing
to do with "being interpreted" somehow differing between Java and
Python.


Alex



More information about the Python-list mailing list