why python is slower than java?

Steve Menard foo at bar.com
Sat Nov 6 00:12:04 EST 2004


Mike Meyer wrote:
> finite.automaton at gmail.com (Lonnie Princehouse) writes:
> 
> 
>>Yes, wxPython is typically quicker than swing.  It's not fair to use
>>this in a generic Python-vs-Java speed shootout, though, since
>>wxPython is just a wrapper around wxWidgets' C++ code; you're really
>>comparing C++ vs. Java here.
> 
> 
> Is it unfair to compare Python dictionaries to Java HashTables because
> Python is using hand-tuned C where Java is using Java? I'd say that's
> a perfectly fair comparison. If that's fair, what's unfair about
> comparing graphics toolkits that happen to be written in C rather than
> Python (is there a graphics toolkit written in Python?).
> 
> That's *how* interpreted languages manage to compete with compiled
> languages - they perform the common operations in hand-tuned compiled
> code. That people tend to write Java libraries in Java rather than C
> just means they're going to get slower libraries.
> 
> 
>>AFAIK the major two reasons for Python's relative slowness are that
>>it's interpreted and dynamically typed.
> 
> 
> Java is interpreted just like Python is. The only difference is that
> Java splits the compiler and VM implementation into two different
> binaries.
> 
>         <mike

Actually java has not been interpreted for quite a few years. Java today 
is compiled to native code at runtime (JIT), exactly like what Psyco 
tries to do for Python. This means the only things that (today) makes a 
java program slower than a C program are Java's added safety features ( 
Bounds-checking on arrays and garbage collection to name but two).

Java's speed and Python's speed are not absolute values. Java IS faster 
than python when it comes to CPU-intensive operations. IF you given 
problem is heavily IO-bound, then python will be just as fast as Java. 
Also, if you are writing a GUI application, your program will spend most 
of its time waiting for user-input and not much difference will be 
noticed. Python may even win out in that case since it's GUI are 
typically platform-tuned C/C++ libraries wrapped in Python.


Steve



More information about the Python-list mailing list