Python 3.2 vs Java 1.6
orasnita at gmail.com
Sat Apr 9 13:05:45 CEST 2011
From: "Steven D'Aprano" <steve+comp.lang.python at pearwood.info>
> On Sat, 09 Apr 2011 01:32:17 +1000, Chris Angelico wrote:
>> On Sat, Apr 9, 2011 at 1:21 AM, km <srikrishnamohan at gmail.com> wrote:
>>> Hi All,
>>> How does python 3.2 fare compared to Java 1.6 in terms of performance ?
>>> any pointers or observations ?
>> Hi All,
>> How do apples compare to oranges in terms of performance?
> Fair point. The two languages are not really aimed at the same target.
> Python tends to optimize for development time, Java tends to optimize for
> execution time (although Java's expensive start up usually makes it
> prohibitive for small, lightweight programs).
> Python tends to be between 1-100 times slower than Java, depending on
> what you're trying to do. Have a look at the programming language shoot-
> Don't jump to conclusions:
Especially don't jump to conclusions, because those tests are not relevant at all for most projects you might need to do.
If you need to create programs for biotechnology or math, then those tests may give you a good image, but otherwise they are not very useful because when you create a program in Python, or Perl, Ruby... they might use other modules which may be pure python/perl/ruby/... code, and they might be not optimized for speed, or they can be written in C and be super-optimized, but that won't mean that Python/Perl/Ruby is fast, or that they consume less resources.
I've seen that the tests used are:
fasta benchmark : Generate and write random DNA sequences
regex-dna benchmark : Match DNA 8-mers and substitute nucleotides for IUB codes
reverse-complement benchmark : Read DNA sequences - write their reverse-complement
k-nucleotide benchmark : Hashtable update and k-nucleotide strings
mandelbrot benchmark : Generate Mandelbrot set portable bitmap file
pidigits benchmark : Streaming arbitrary-precision arithmetic
binary-trees benchmark : Allocate and deallocate many many binary trees
The spectral norm of a matrix is the square root of the largest eigenvalue of ... where <mat1> is a matrix for which the spectral norm is to be computed
fannkuch-redux benchmark : Indexed-access to tiny integer-sequence
The n-body problem is the problem of predicting the motion of a group of
celestial objects that interact with each other gravitationally.
If there are fast modules for Python that can do these things, that doesn't mean that Python will be faster in general for other things, or if there are no such fast modules that can do these things, this doesn't mean that Python is slow because those tests show that.
It is hard to compare the languages in general, because even if the tests would compare only the pure code programs that don't use C code, if there are fast modules that use C code for a certain language for a certain task, it wouldn't be important that that language is slow, if it has fast modules for the wanted task.
And not only the speed is less relevant in those tests, but the comparison of the resources needed too, and the differences between the sizes of the source code also, because if there is a higher level module for a certain language, the programmer might need to only load that module, eventually initialize an object, and call a method of that object in just a few lines of code.
More information about the Python-list