tags:

views:

286

answers:

5

Possible Duplicate:
is python slower than java/C#?

Ignoring all the characteristics of each languages and focusing SOLELY on speed, which language is better performance-wise?

You'd think this would be a rather simple question to answer, but I haven't found a decent one.

I'm aware that some types of operations may be faster with python, and vice-versa, but I cannot find any detailed information on this. Can anyone shed some light on the performance differences?

+3  A: 

Java is faster than Python. Easily.

Python is favorable for many things; speed isn't necessarily one of them.

References

polygenelubricants
No, Java is not faster as Python, just as it is not greener than Python. A current version of the Sun JRE is probably much faster than a current CPython implementation when running a comparable application, but that doesn't say anything about the Java language or the Python language.
Joachim Sauer
This is incorrect. It depends on the interpreter/compiler.
Michael Aaron Safyan
@Joachim: I suppose if we talk about really big picture stuff, you're right. But currently, the most optimized Java code will outperform the most optimized Python code.
polygenelubricants
Java=SunJava are almost synonyms for all intents and purposes. Its nonsense to talk about abstract things that dont actually run, like python as an idea and the same for java.
mP
@polygenelubricants, not necessarily. For example, Python code that makes heavy use of numpy may very well be faster than the equivalent Java code, as numpy does a huge amount of heavy lifting directly in C.
Michael Aaron Safyan
@mP: What about the [JRockit JVM](http://www.oracle.com/technology/products/jrockit/index.html)? It's very popular in some circles (those that need lightning-fast performance, usually) and it's **not** based on the HotSpot VM at all. Also, many embedded Java systems still don't use code that's somehow derived from the Sun JVM (now OpenJDK).
Joachim Sauer
@Michael: I haven't much experienced with native code, but what if you make the playing field level by having a Java wrapper around the same C code? Would it still be slower?
polygenelubricants
I'll probably delete this answer at some point, but for now I'm enjoying the discussion. Keep going.
polygenelubricants
@Michael: C implementations aren't necessarily the fastest possible. Java implementations can implement optimizations that are simply not possible with C code.
Joachim Sauer
@poly: if you are worried about the down votes just make your answer wiki... but I'm sure the down votes are just from jealous python developers.
Matthew Whited
@Michael - but then we're back to the point that the original question can't be answered. First because 'languages' don't have 'performance', second because it depends on the implementations of a given task (sorting with O(n²) in Java is slower then sorting with O(n log n) in python)... I think poly's answer is at least much better then the question.
Andreas_D
@Matthew: I don't think Python developers have anything to be jealous about. In many scenarios, speed isn't the most important thing. Readability, expressibility, etc is much more important than speed. I'm not knocking off Python at all, I think it's a wonderful language (what little I know of it). You just don't choose it because you think it's going to be faster than Java.
polygenelubricants
@polygenelubricants, indeed, if you used the same native code, then you would be in the same place, which, in fact, supports my point which is that there are too many parameters to state that one is faster than the other. It depends entirely on implementation.
Michael Aaron Safyan
@polygene: I agree that the most optimized pure Java code will *currently* outperform the most optimized pure Python code. The thing is that advantages in the JVM technology could give Jython the ability to come very near the performance of Java and possibly even bypass it. It's a shifting landscape and explaining any comparison without indicating that it's subject to constant change can be misleading (Java used to be "much slower than C" as well, some time ago).
Joachim Sauer
@Andreas, that may be so, but should we give incorrect answers just to give an answer? If I don't know something, I think I have a professional and moral obligation to say "I don't know" rather than give a false answer just for the sake of having an answer. Don't you?
Michael Aaron Safyan
I was only making a joke... I don't care what language you use as long as it works (I mean hell... write a webpage in assembly if you like.) But I would be willing to bet that you saying Java are faster than Python hurt a few zealots’ feelings. I got in a similar annoyance when I asked if I should change from SVN to GIT and then said that I was going to stay with SVN. Some people vote with their hearts instead of their heads. But it's their life so they may do as they wish.
Matthew Whited
@Joachim, @Michael: I think there's an allowance to give an answer on what is reasonably true, generally speaking, right now. Otherwise, nothing can be answered. There is very little universal eternal truths in engineering fields.
polygenelubricants
@poly: There *are* a few universal truths. If you ask what a specific language construct does, then I can tell you. Otherwise: sure, give the answer, but take care not to present it as an universal truth.
Joachim Sauer
+3  A: 

Different languages do different things with different levels of efficiency.

http://shootout.alioth.debian.org has a whole load of different programming problems implemented in a lot of different languages.

Oli
A: 

There is no good answer as Python and Java are both specifications for which there are many different implementations. For example, CPython, IronPython, Jython, and PyPy are just a handful of Python implementations out there. For Java, there is the HotSpot VM, the Mac OS X Java VM, OpenJRE, etc. Jython generates Java bytecode, and so it would be using more-or-less the same underlying Java. CPython implements quite a handful of things directly in C, so it is very fast, but then again Java VMs also implement many functions in C. You would probably have to measure on a function-by-function basis and across a variety of interpreters and VMs in order to make any reasonable statement.

Michael Aaron Safyan
A: 

PYTHON!!! You can compute @ really faster speed and with greater accuracy!

1s2a3n4j5e6e7v
It depends entirely on implementation.
Michael Aaron Safyan
obviously things finally come to the point of implementation :)
1s2a3n4j5e6e7v
A: 

If you ignore the characteristics of both languages, how do you define "SPEED"? Which features should be in your benchmark and which do you want to omit?

For example:

  • Does it count when Java executes an empty loop faster than Python?
  • Or is Python faster when it notices that the loop body is empty, the loop header has no side effects and it optimizes the whole loop away?
  • Or is that "a language characteristic"?
  • Do you want to know how many bytecodes each language can execute per second?
  • Which ones? Only the fast ones or all of them?
  • How do you count the Java VM JIT compiler which turns bytecode into CPU-specific assembler code at runtime?
  • Do you include code compilation times (which are extra in Java but always included in Python)?

Conclusion: Your question has no answer because it isn't defined what you want. Even if you made it more clear, the question will probably become academic since you will measure something that doesn't count in real life. For all of my projects, both Java and Python have always been fast enough. Of course, I would prefer one language over the other for a specific problem in a certain context.

Aaron Digulla
Why the downvote?