I ran across [Glyph Lefkowitz’ Python and Java tests] while doing some research on integrating Python into non-scripting languages. Since the versions Glyph used were a little old, I became curious about how my current versions would pan out.
Note: As a coder who's worked a bit in both languages, I'm heavily biased towards Python !
My test platform was an IBM laptop with a 500 MHz Pentium III processor and 192 MB of memory, running Debian GNU/Linux, kernel version 2.4.18. I used Python version 2.2.2 (installed from the Debian package) and the Java2 SDK version 1.4.1 (installed from Sun's web site, not from a Debian package).
A few notes about the table :
I ran my tests from behind an HTTP proxy, so I left out the URLTest, because I didn't have time to figure out how to deal with proxies.
The numbers in the third column display the absolute time difference between the two tests ; negative numbers indicate tests where Python was faster than Java.
The numbers in the fourth column indicate the relative speed difference between the two tests ; numbers smaller than 1 indicate a test where Python was faster.
All numbers reflect the number of significant figures returned by the time function, I hope.
Although there is no explicit license statement on Glyph's code, I assume it is distributed in the sense of the Python License or something similar, so I have [repackaged his code], with my small modifications for updated versions.
One thing that Glyph comments on but does not quantify is the amount of code required for each of the tests. It is striking, from looking at his site, how small the Python code example is when compared with the Java code. I decided to try to quantify this, as I believe it is a significant factor when writing larger programs. All file sizes are measured in bytes and reflect source code size only. (Compiled code is not particularly a fair comparison, I think, since Java is byte-compiled and Python can be byte-compiled.)
|NativeTest b||172 (563)||382||210 (-181)||2.22 (0.679)|
A few notes about this table :
The NativeTest is composed of (a) test code written in Java or Python and (b) native code written in C. I decided it would be more illustrative to split the two parts and compare them separately.
Writing native code for Java involves writing a C file by hand and then using the javah program to automatically generate a C header file needed for compiling. The numbers in parentheses reflect the code sizes for Java that include this automatically generated file. This header file does not need to be written by hand, but it does increases the size of the code involved.
Python code, for these tests, is fairly consistently one fourth the size of Java code. I find this interesting and would like to see some more real–life code comparisons to see if such a strong trend holds.
None of the code for these tests, except for the generated native header file for Java's NativeTest, includes any comments.