Comparing Python and Java: Performance & Standard Libs

In summary: This is what happens in a just in time compiler.- WarrenIn summary, the presenter claimed that Python is almost as complete as Java with respect to standard library components. Python is often faster than Java, and has fewer platform dependencies.
  • #1
neurocomp2003
1,366
3
Any one have any opinions on the differences between these two language (and their closeness to C)...

chroot posted about python being almost as complete as java interms of standard libs. I attended a presentation which seemed to verify that claim though you have to download some of the added libs like numpy,scipy,wxpython.

Is there a performance difference between the two?

My goal is to try to minimize the number of packages to be downloaded for my application which currently uses both java/python. Not sure why since wxpython seems to be platform independent but they use java's awt/swing because of clientside platform independence.
 
Technology news on Phys.org
  • #2
Python's a better language, all around, in my opinion. The syntax, built-in data types, weak-typing, and other features just make it incredibly fluid and flexible.

The standard library is certainly as big as Java's. The only downside is that it's rather messy, since it was written by a ton of different people. There are no universal naming conventions -- some people use initial-capped class names, some use all lowercase. Some have oscure names that make them hard to search for. (If you were looking for an object serialization system, would the word 'pickle' come to mind?)

Python's performance is often much better than Java's. Experienced Python programmers can write code such that the processor spends most of its time in the underlying native, optimized C implementation, rather than in the interpreter code. The best way to use Python is as high-level coordination of native modules like NumPy and wxPython. I hesitate to call Python "glue," since you can do almost anything in pure Python. On the other hand, if speed is essential, try to use libraries with native implementations. In my real-world experience, Java is significantly slower than Python.

You can even compile virtually any Python program to a native executable with free, open-source tools like Pyrex. There are some similar tools for Java, but they're not nearly as capable.

- Warren
 
Last edited:
  • #3
Why does Python have such a poor performance on the language shoot out page?

http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang=java&lang2=python

I tought that the power of Java lies in the VM (it does dynamic optimization rather than compile time static optimization).
 
Last edited by a moderator:
  • #4
From what I can tell, these people implemented CPU- and memory-intensive algorithms in pure Python. That's a very good way to ensure your Python program is slow. I'd be much more interested in seeing a comparison against Python programs that use native libraries (like NumPy) in a way that a real programmer would use them.

- Warren
 
Last edited:
  • #5
Does Python support just-in-time compilation? A second run of a Java application is largely native due to JIT. The values used in the benchmark were probably on runs after JIT has taken place, considering it's a server application.

Otherwise it has probably to do with optimization like haki mentioned (where Java's rigorous yet verbose standards might be a factor).
 
Last edited:
  • #6
There any many different implementations of Python, some which do JIT and some which do not.

- Warren
 
  • #7
The non-JIT Python implementations have to be considerably slower than Java 6.
 
  • #8
That depends on how the code was written, and how well the programmer takes advantage of natively-coded modules.

- Warren
 
  • #9
Same goes for Java though.
 
  • #10
haki said:
Why does Python have such a poor performance on the language shoot out page?

http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang=java&lang2=python

I tought that the power of Java lies in the VM (it does dynamic optimization rather than compile time static optimization).

Those measurements are OUT-OF-DATE!

Here are up-to-date measurements -

http://shootout.alioth.debian.org/u32/compare.php?lang=python3&lang2=java"

http://shootout.alioth.debian.org/u32q/compare.php?lang=python3&lang2=java"

http://shootout.alioth.debian.org/u32/compare.php?lang=pypy&lang2=java"
 
Last edited by a moderator:
  • #11
chroot said:
From what I can tell, these people implemented CPU- and memory-intensive algorithms in pure Python. That's a very good way to ensure your Python program is slow. I'd be much more interested in seeing a comparison against Python programs that use native libraries (like NumPy) in a way that a real programmer would use them.

It's a good way to look at the performance of pure Python ;-)
 
  • #12
-Job- said:
Does Python support just-in-time compilation? A second run of a Java application is largely native due to JIT. The values used in the benchmark were probably on runs after JIT has taken place, considering it's a server application.

No - there's no link between a second run of a Java application and a previous run.

We can force there to be a link by starting Java and then repeatedly running the application once, twice, ... without stopping Java - http://shootout.alioth.debian.org/help.php#measure" .

Java Hotspot JIT compiles hot methods to native code and switches to those compiled methods while the program is being run.
 
Last edited by a moderator:
  • #13
chroot said:
There any many different implementations of Python, some which do JIT and some which do not.

- Warren

Which Python JIT implementations are ready for production use?
 
  • #14
Python is a programming language that let's you work more quickly and integrate your systems more effectively. It supports multiple programming paradigms (primarily object oriented, imperative, and functional) and features a fully dynamic type system and automatic memory management.
 

1. What are the main differences in performance between Python and Java?

Python and Java are both high-level programming languages, but they have different approaches to performance. Java is typically considered faster and more efficient than Python due to its compiled nature. Python, on the other hand, is an interpreted language, which means it is executed line by line, making it slower in comparison. However, with advancements in technology, the performance gap between the two languages has become smaller.

2. How do the standard libraries of Python and Java compare?

The standard libraries of Python and Java are both extensive and provide a wide range of functionalities. However, Java's standard library is considered to be more comprehensive and robust, with a larger number of built-in functions and classes. Python's standard library, although not as extensive, is known for its readability and ease of use.

3. Which language is better for web development, Python or Java?

Both Python and Java are commonly used for web development, but they have different strengths. Python is known for its simplicity and readability, making it a popular choice for building web applications. On the other hand, Java is often used for enterprise-level web development due to its scalability and robustness. Ultimately, the best language for web development depends on the specific project and its requirements.

4. Can Python and Java be used together in a project?

Yes, it is possible to use both Python and Java in the same project. In fact, many developers use both languages to take advantage of their respective strengths. For example, Python can be used for rapid prototyping and data analysis, while Java can be used for building the final product with better performance and scalability.

5. Which language is easier to learn, Python or Java?

This is a subjective question as it depends on the individual's learning style and background. However, many beginners find Python to be easier to learn due to its simple syntax and readability. Java, on the other hand, has a steeper learning curve and requires a solid understanding of object-oriented programming concepts. Ultimately, the best language to learn is the one that aligns with your goals and interests.

Similar threads

  • Special and General Relativity
3
Replies
75
Views
3K
  • STEM Academic Advising
Replies
4
Views
10K
  • STEM Academic Advising
Replies
13
Views
2K
  • Special and General Relativity
Replies
6
Views
5K
  • Beyond the Standard Models
Replies
10
Views
2K
Replies
13
Views
2K
  • Special and General Relativity
Replies
5
Views
4K
  • STEM Academic Advising
Replies
10
Views
3K
Back
Top