Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python vs. Java performance (runtime speed) [duplicate]

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?

like image 398
Bijan Avatar asked Jun 15 '10 11:06

Bijan


People also ask

Does Python run faster than Java?

Python programs are generally expected to run slower than Java programs, but they also take much less time to develop. Python programs are typically 3-5 times shorter than equivalent Java programs. This difference can be attributed to Python's built-in high-level data types and its dynamic typing.

How many times faster is Java than Python?

To compare the runtime speed of two programming languages, such as Java and Python, programmers must focus on specific implementations. With that in mind, Java is much faster than Python. Historically, Java was up to 25+ times faster, but that has since changed following the release of Python 3.

Does Python use more memory than Java?

JVM has a JIT compiler which optimizes code that is called frequently. This allows Java programs to be competitive with C programs for some use-cases. Generally, Java programs are 3x slower than their C counterparts. Python: Python programs also take more memory than C/C++ programs but not as much as Java.

Which is faster Java or Python or C?

Execution TimeJava is much faster than Python in terms of speed of execution but slower than C++.


2 Answers

Java is faster than Python. Easily.

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

References

  • python.org/Language Comparisons
    • C++ vs Java vs Python vs Ruby : a first impression
    • A subjective analysis of two high-level, object-oriented languages: Comparing Python to Java
like image 99
polygenelubricants Avatar answered Sep 21 '22 23:09

polygenelubricants


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.

like image 27
Aaron Digulla Avatar answered Sep 21 '22 23:09

Aaron Digulla