why python is slower than java?

John Doe atterdan at yahoo.com
Fri Nov 5 04:28:35 EST 2004


On Fri, 05 Nov 2004 05:58:09 +0000, Maurice LING wrote:

> This may be a dumb thing to ask, but besides the penalty for dynamic 
> typing, is there any other real reasons that Python is slower than Java?
> 
> maurice

Hi Maurice,
the issue is compiling and bytecode. Python and Java compile source to
their own bytecodes. Bytecode is a binary that is portable between many
Operating Systems. Some time in 1999 (I think) IBM developed a jit or
Just In Time compiler for Java (Apple invented the JIT concept earlier to
make 68000 code work on their new line of PowerPC Macs). 

The JIT compiler compiled java to both bytecode and native OS opcode. This
offered increase speed on the second + runs. The binary was suppose to be
compiled into a block containing bytecode and opcode. If the java runtime
noted that the opcode segment was 'native', it was suppose to run it, over
the bytecode. This gives the 'faster' perception. 

Of course some company, afraid their developers might build there GUI apps
with java, over their native mode (thus making their application work
anywhere Java worked) went ahead and developed a version of the java
compiler that stripped out the bytecode. This made the binary
smaller, but locked it to one OS/arch. You can guess about which
corporation that was. Lawsuits followed. The company in question lost and
decided to drop Java for their own version of Java, JavaLite, sometimes
called 'see' 'sharp'. 

Now as to speed... If you want speed, develop in Python or Perl to
get the form of your program. Development time is faster, even if the
execution is slow. Both provide OOP bindings. Once the program is up and
running, you can use profiling to determine which parts of your
interpreted code is slowest and most often used. These you rewrite as
C/C++ code and call them from within python. 

In this way version 1.0 is all python. v1.1 has 20% C++; v1.2 is 34% C++
... until v2.0 is all C++. Each upgrades is faster, but does not introduce
any new functionality and the risks that new functions imply.

If you were faithful to this concept, version 3 requires you to use the
oldest python branch who's functions will not be modified, to start
development. Could be v1.1 or 1.9. 

C/C++ is for speed, not development.

Dan Atterton
atterdan at yahoo.com






More information about the Python-list mailing list