Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > why python is slower than java?

Reply
Thread Tools

why python is slower than java?

 
 
Maurice LING
Guest
Posts: n/a
 
      11-05-2004
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
 
Reply With Quote
 
 
 
 
Bryan
Guest
Posts: n/a
 
      11-05-2004
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


at work, we use java and python. we have projects using swing and others using wxpython. we have applications that do
intensive io and others that do intensive cpu. we have not found that python is slower than java. in fact, when it
comes to gui's, our swing apps take "forever" to startup and when when garbage collector starts, the whole app just
freezes for about 15 seconds. our wxpython apps, start right up and "feel" faster and snappier. can you show an
example of where python's "slow" speed as compared to java's "fast" speed has negatively impacted your application or
has been noticable in any way? i know this is a trolling question you have posted, but i'm actually very interested
knowing why you have said this.

thanks,

bryan
 
Reply With Quote
 
 
 
 
Maurice LING
Guest
Posts: n/a
 
      11-05-2004

> at work, we use java and python. we have projects using swing and
> others using wxpython. we have applications that do intensive io and
> others that do intensive cpu. we have not found that python is slower
> than java. in fact, when it comes to gui's, our swing apps take
> "forever" to startup and when when garbage collector starts, the whole
> app just freezes for about 15 seconds. our wxpython apps, start right
> up and "feel" faster and snappier. can you show an example of where
> python's "slow" speed as compared to java's "fast" speed has negatively
> impacted your application or has been noticable in any way? i know this
> is a trolling question you have posted, but i'm actually very interested
> knowing why you have said this.
>
> thanks,
>
> bryan


Thanks, lets just say that I have no interest in trolling.

1st of all, I thought it is somehow common knowledge that python is
slower than java in many cases. Though I may be wrong... When I do a
Google search, this came up...

http://twistedmatrix.com/users/glyph...n-vs-java.html

although http://page.mi.fu-berlin.de/~prechel.../jccpprtTR.pdf
showsjust the opposite.

What I need to work on now is something that requires speed (and dealing
with files), without user's intervention. So the part about users' delay
time is not in the equation. My choices boils down to Python or Java.

Cheers
maurice
 
Reply With Quote
 
Bryan
Guest
Posts: n/a
 
      11-05-2004
Maurice LING wrote:
>
>> at work, we use java and python. we have projects using swing and
>> others using wxpython. we have applications that do intensive io and
>> others that do intensive cpu. we have not found that python is slower
>> than java. in fact, when it comes to gui's, our swing apps take
>> "forever" to startup and when when garbage collector starts, the whole
>> app just freezes for about 15 seconds. our wxpython apps, start right
>> up and "feel" faster and snappier. can you show an example of where
>> python's "slow" speed as compared to java's "fast" speed has
>> negatively impacted your application or has been noticable in any
>> way? i know this is a trolling question you have posted, but i'm
>> actually very interested knowing why you have said this.
>>
>> thanks,
>>
>> bryan

>
>
> Thanks, lets just say that I have no interest in trolling.
>
> 1st of all, I thought it is somehow common knowledge that python is
> slower than java in many cases. Though I may be wrong... When I do a
> Google search, this came up...
>
> http://twistedmatrix.com/users/glyph...n-vs-java.html
>
> although http://page.mi.fu-berlin.de/~prechel.../jccpprtTR.pdf
> showsjust the opposite.
>
> What I need to work on now is something that requires speed (and dealing
> with files), without user's intervention. So the part about users' delay
> time is not in the equation. My choices boils down to Python or Java.
>
> Cheers
> maurice


but you aren't saying exactly _what_ requires speed and exactly what your requirements for the project is. you are being
way too general here for anyone to really help you. as for working with files, i much rather do that in python than
java. i may be wrong, but i thought java's file IO was pretty much a thin wrapper over c. so i don't think you will
have any speed problems with python's file IO compared to java's. also, just for fun, write the following fully
working python program in java:

import time
t = time.time()
s = open('in.txt').read()
open('out.txt', 'w').write(s)
print time.time() - t

(by the way...i was able to write the above lines of python code without referring to a manual

if it's not too much trouble, could you please post your code here along with the time results for the above code and
your java code? you can test a small file and a large one.

thanks,

bryan
 
Reply With Quote
 
Christopher Koppler
Guest
Posts: n/a
 
      11-05-2004
On Fri, 05 Nov 2004 07:11:33 +0000, Maurice LING wrote:

> What I need to work on now is something that requires speed (and dealing
> with files), without user's intervention. So the part about users' delay
> time is not in the equation. My choices boils down to Python or Java.


Speed in what area? Dealing with files, is it a heavily I/O-based program?
If so, choice of programming language will very probably hardly impact
performance (well, depending of course on exactly you want to do, there
may of course be differences...).
Or do you want to crunch numbers? Python has great extensions for that,
written in highly optimized C. Come to think of it, Python has great
built-in datatypes and extensions for all manner of things, written in
highly optimized C. So even if your application wants to do some heavy
processing of <whatever> that doesn't depend on external factors like I/O
speed, the network or user interaction, Python will generally be fast
enough.
And as for the statically typed nature of Java providing speed benefits,
take a look at Psyco, which often (but not always) helps enormously.

So everything boils down to two points: what exactly you want to do - if
you can tell us that, someone better qualified and less biased than
myself might actually be able to offer you concrete advice on what to
choose - and as always: premature optimization is the root of all evil

--
Christopher

 
Reply With Quote
 
John Doe
Guest
Posts: n/a
 
      11-05-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
http://www.velocityreviews.com/forums/(E-Mail Removed)



 
Reply With Quote
 
Israel Raj T
Guest
Posts: n/a
 
      11-05-2004
Maurice LING <(E-Mail Removed)> writes:

> 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?


Do you have any data to support this ?
On Windows XP, Windows NT and Linux (Gentoo ), I have consistently
found python apps using wxpython to be far faster to load
and to be far more responsive than Java apps.
 
Reply With Quote
 
Israel Raj T
Guest
Posts: n/a
 
      11-05-2004


http://dada.perl.it/shootout/craps.html

On the CPU score, Java scores 28.4 while Python is within cooee at 27.
(bigger is better )

On the updated version at http://shootout.alioth.debian.org/craps.php,
Python beats at least two java implementations.
 
Reply With Quote
 
EP
Guest
Posts: n/a
 
      11-05-2004
John Doe wrote (posthumously?):

> 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.



Am I the only one to think this works, but makes no sense?

If one is to migrate their Python code to C++, one ends up with C++ code, which is great unless there is that (not so very rare) event where one wants to add new features, address new requirements, etc., etc. Applications need to evolve. If the finished code is going to be C++, one might just as well program in C++ from the start instead of aportioning mindshare between the two languages. Mindshare devoted to thinking in a second language might instead be devoted to thinking about the application.

Python seems to exemplify living code and since good applications have a life of their own, shouldn't the code live as well?

Dipping into C++ for program hotspots seems like good pramaticism, but at the expense of the simplicity and clarity that is otherwise Pythonic.

Fast Python is an answer, a patchwork of programming languages is a work around.


Eric

I won't say that Python needs to be faster, but imagine Python running as fast as C++ without any special tricks and you can envision the opportunities lost due to Python lacking blazing speed.

 
Reply With Quote
 
Ian Bicking
Guest
Posts: n/a
 
      11-05-2004
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?


Python is generally late-bound, which means much more happens at runtime
compared to Java. For instance, consider accessing an attribute,
"self.x". In Java you know what the class is shaped like, exactly.
Usually this turns into some bytecode like "access the variable of self,
at offset 3". I don't know any of the details, but that's the general gist.

Similarly, there's many other optimizations where you can know at
compile time exactly what functions are called, how variables are
stored, etc. Using that information, you can do optimizations like
inline code. In the same places in Python, you are typically doing one
(or several!) hashtable lookups based on the variable or attribute name.

But even in Java there are limits. Because of interfaces and subclasses
you can know the shape of self/this, but you can't know the exact shape
of the objects around you (C++ is more aggressive in this respect, and
often can determine the exact shape; but in the process it's dangerous
to put together different pieces of compiled code when they don't know
about each other, which is why binary interfaces there are fragile).
Anyway, Java does a lot of the same stuff as Python when the exact type
is determined at runtime (which is frequently). This is where JIT comes
in, doing the optimizations at runtime; it is still limited, as it
cannot guarantee the type of the objects in the system, but must check
them each time before using the optimized path. And, actually, Python
can do the same sort of things with psyco. It's still harder in Python,
and the end result not as effective, but it's one among many tools.

If Java wasn't doing any optimizations, I don't think it would be
significantly faster than Python.

Also note that Python assimilates external (C, Fortan, etc) libraries
much better than Java seems to. In an entire system, Python can easily
be faster because Java includes many slow libraries (slow compared to
equivalent libraries available in Python). E.g., Swing is much slower
than wxPython.

Anyway, that's my take. I'm no authority, as I've never seriously used
Java, and haven't done any tests, nor spent anytime looking at the
bytecodes, etc.

--
Ian Bicking / (E-Mail Removed) / http://blog.ianbicking.org
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: HELP! Ping getting slower and slower and slower! Paul Computer Information 2 04-03-2012 05:58 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Why do VHDL gate level models simulate slower than verilog abilash VHDL 1 05-17-2005 04:46 AM
XPath queries getting slower and slower... Andre Charbonneau Java 0 02-15-2005 05:04 PM
Dialup modem connects at slower and slower speeds Sharon Sharp Computer Support 7 10-13-2004 02:51 PM



Advertisments