473,699 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

why python is slower than java?

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
Jul 18 '05 #1
114 9843
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
Jul 18 '05 #2
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
Jul 18 '05 #3
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
Jul 18 '05 #4
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

Jul 18 '05 #5
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
at******@yahoo. com

Jul 18 '05 #6
Maurice LING <ma*********@ac m.org> 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.
Jul 18 '05 #7


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 .
Jul 18 '05 #8
EP
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 wantsto 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.

Jul 18 '05 #9
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 / ia**@colorstudy .com / http://blog.ianbicking.org
Jul 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
4997
by: Catalin | last post by:
How can I make executables with python? I found some utilities that claim they can do something like that like Installer and py2exe but they actualy pack the code in a huge arhive! This solves the problem of giving python programs to users who don't have python but doesn't solve the problem of the source "secrecy" (copyright). And the programs also run much slower and become extremely big compared to a normal C++ program for example. I...
49
2844
by: Ville Vainio | last post by:
I don't know if you have seen this before, but here goes: http://text.userlinux.com/white_paper.html There is a jab at Python, though, mentioning that Ruby is more "refined". -- Ville Vainio http://www.students.tut.fi/~vainio24
30
2777
by: Stuart Turner | last post by:
Hi Everyone, I'm working hard trying to get Python 'accepted' in the organisation I work for. I'm making some good in-roads. One chap sent me the text below on his views of Python. I wondered if anyone from the group could give me some advice on how to respond / if they had been in a similar position. Any help appreciated, Thanks in advance,
118
6708
by: 63q2o4i02 | last post by:
Hi, I've been thinking about Python vs. Lisp. I've been learning Python the past few months and like it very much. A few years ago I had an AI class where we had to use Lisp, and I absolutely hated it, having learned C++ a few years prior. They didn't teach Lisp at all and instead expected us to learn on our own. I wasn't aware I had to uproot my thought process to "get" it and wound up feeling like a moron. In learning Python I've...
34
3678
by: Anthony Irwin | last post by:
Hi All, I am currently trying to decide between using python or java and have a few quick questions about python that you may be able to help with. #1 Does python have something like javas .jar packages. A jar file contains all the program files and you can execute the program with java -jar program.jar I am sort of hoping python has something like this because I feel it
18
7430
by: Jens | last post by:
I'm starting a project in data mining, and I'm considering Python and Java as possible platforms. I'm conserned by performance. Most benchmarks report that Java is about 10-15 times faster than Python, and my own experiments confirms this. I could imagine this to become a problem for very large datasets. How good is the integration with MySQL in Python?
16
1878
by: Raxit | last post by:
Hi, i was reading/learning some hello world program in python. I think its very simillar to Java/C++/C#. What's different (except syntax) ? what can i do easily with python which is not easy in c++/java !? Tnx, Raxit
0
8623
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9184
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8931
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7767
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6539
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5878
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4386
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2359
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2014
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.