Java Vs. Python 
Author Message
 Java Vs. Python

I have an an atypical Java vs. python question.  To summarize, here's our
scenarios: 1) We license Java and embed what we get from Sun into our
application 2) We embed Python into our application.  The question is, which
will execute faster for the equivalent code on the same machine?

As a background, our project involves distributed automated manufacturing (see
http://www.*-*-*.com/ ~msl/minifactory/newminfact.html if you are interested).
We need an interpreted language primarily to script the programs for each agent
in the factory, in which case execution time is not a real problem.  We are
also toying around with sending pieces of code between cooperating agents which
will be run inside an agent A's control loop to predict agent B's state so that
we can reduce how often agent B has to send agent A its state.  In this
situation, the code (probably 10-100 floating point operations) may have to run
at 100Hz or more, in which case efficiency of execution becomes critical, since
we don't want to bog down the whole processor just executing the state
predictor.

I'm fairly new to both Python and Java, but the unsupported statements I've
seen have hinted that Java code executes faster than the equivalent Python
code.  Is this a fundamental fact due to Python's run-time dynamic typing
vs. Java's static typing?  Is this just true for the highly optimized and
banged-on Java compilers you might find in Netscape or Explorer, or is it also
true for the code that comes straight from Sun?  

                                        Jay Gowdy



Mon, 24 Apr 2000 03:00:00 GMT  
 Java Vs. Python


Quote:

> I have an an atypical Java vs. Python question.  To summarize, here's our
> scenarios: 1) We license Java and embed what we get from Sun into our
> application 2) We embed Python into our application.  The question is, which
> will execute faster for the equivalent code on the same machine?

> As a background, our project involves distributed automated manufacturing (see
> http://www.*-*-*.com/ ~msl/minifactory/newminfact.html if you are interested).
> We need an interpreted language primarily to script the programs for each agent
> in the factory, in which case execution time is not a real problem.  We are
> also toying around with sending pieces of code between cooperating agents which
> will be run inside an agent A's control loop to predict agent B's state so that
> we can reduce how often agent B has to send agent A its state.  In this
> situation, the code (probably 10-100 floating point operations) may have to run
> at 100Hz or more, in which case efficiency of execution becomes critical, since
> we don't want to bog down the whole processor just executing the state
> predictor.

> I'm fairly new to both Python and Java, but the unsupported statements I've
> seen have hinted that Java code executes faster than the equivalent Python
> code.  Is this a fundamental fact due to Python's run-time dynamic typing
> vs. Java's static typing?  Is this just true for the highly optimized and
> banged-on Java compilers you might find in Netscape or Explorer, or is it also
> true for the code that comes straight from Sun?  

>                                         Jay Gowdy

The short answer is:

        It depends.

Java has static typing and on most platforms has a more optimized
byte code interpreter.

Both languages have "native" modules that are usually coded in C or C++.
If you're calling routines in those modules it's going to run fast.
( Python has some numerical matrix extensions for example. )
Python probably has more native modules than Java -- a lot of JDK
classes look to be coded IN Java. ( again -- this will vary with
the classes and libraries distributed with any particular VM )

In both, you have the option of writing your own native modules.
( But for both, this downgrades the ability to migrate code --
  unless you use ActiveX or something, you need to install the
  native modules 'manually' . )

Someone said that most of the best compiler hackers in the US have
been hired by various companies to work on Java: Java VM performance
has had about a 10 fold inprovement since the language has been
around, and it seems likely that it will get pretty close to C++
performance in the next couple of years.

 Have you looked at Jim Hugunin's paper on the python.org website ?
 It's possible to have "the best of both worlds" !


---|  Department of Molecular Physiology and Biological Physics  |---
---|  University of {*filter*}ia             Health Sciences Center  |---
---|  P.O. Box 10011            C{*filter*}tesville, VA  22906-0011  |---
All power corrupts and obsolete power corrupts obsoletely." - Ted Nelson



Mon, 24 Apr 2000 03:00:00 GMT  
 Java Vs. Python

Quote:

> I have an an atypical Java vs. Python question.  To summarize, here's our
> scenarios: 1) We license Java and embed what we get from Sun into our
> application 2) We embed Python into our application.  The question is, which
> will execute faster for the equivalent code on the same machine?

What you're really asking is should you embed a Python or a Java VIRTUAL
MACHINE (VM) into your application.  The Java VM is designed for much
higher performance than the Python VM.  When doing raw floating point
calculations I've found this performance difference to range between
10X-1000X.  The difference is intrinsic to the design of the bytecodes
for these two VM's and is extremely unlikely to go away.  (Side note: if
you're interested in using embedded microcontrollers, a number of
manufacturers are starting to sell them with JVM kernels builtin).

The next important question to ask is what language you should use to
write for this VM.  By choosing the Java VM you allow yourself the
ability to write your actual programs in both Python (where programmer
time is more important than execution time) and Java (where milliseconds
count).  I personally think this gives you the best of both worlds.

If you're interested in more information on using Python and Java
together (rather than choosing one or the other) you should check out
JPython at:

http://www.python.org/jpython

I hope this information is helpful - Jim Hugunin



Wed, 26 Apr 2000 03:00:00 GMT  
 Java Vs. Python


Quote:

>code.  Is this a fundamental fact due to Python's run-time dynamic typing
>vs. Java's static typing?  Is this just true for the highly optimized and
>banged-on Java compilers you might find in Netscape or Explorer, or is it also
>true for the code that comes straight from Sun?  

Your mileage will DEFINITELY vary.  Windows platforms seem to have the
most optimized JVMs.  There are even some JVMs that are trying to do
really slick tricks to get code that runs FASTER than native C++ code.

However, the Sun JDK on Linux I found was SIGNIFICANTLY slower and
leaked a *LOT* of memory.  If it weren't for that, I wouldn't even
be using Python now.  I like Java as a language, but most of the
machines I deal with are Linux and the Linux JDK just kind of sucks.

In the end, unless you're using Linux (and believe me), you'll just have
to do some tests running the kind of code you're talking about and see
wether it's going to be anywhere near fast enough.

Sean
--
 What no spouse of a programmer can ever understand is that a programmer is
 working when he's staring out the window.

URL: <http://www.tummy.com/xvscan> HP-UX/Linux/FreeBSD/BSDOS scanning software.



Wed, 26 Apr 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Java vs Python Benchmarks: Java is faster

2. GUI advice -- AWT vs Tk, Java vs python

3. Java vs Python

4. AWT/Java vs Python/Tk/Tix

5. Cellular automata benchmarks: Java vs C++ vs Java vs C++

6. Tcl vs Python vs Java :: Apologies

7. python vs java (vs tcl?) benchmarks

8. Tcl vs Python vs Java :: Apologies

9. Python Binding [Was: Re: PYTHON VS. PERL VS. TCL ]

10. Java vs Python ... ???

11. ST vs Java vs ST vs ....

12. Lisp vs Java vs C++ vs...

 

 
Powered by phpBB® Forum Software