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).
| Test | Java | Python | P-J | P/J |
| ConsoleTest | 23.35 | 18.01 | -5.34 | 0.7713 |
| HashTest | 2.08 | 3.96 | 1.88 | 1.90 |
| IOTest | 5.13 | 23.26 | 18.13 | 4.53 |
| ListTest | 1.48 | 5.57 | 4.09 | 3.76 |
| NativeTest | 2.43 | 3.98 | 1.55 | 1.64 |
| NoTest | 1.01 | 0.07 | -0.94 | 0.07 |
| ObjectTest | 2.42 | 110.02 | 107.60 | 45.5 |
| SpeedTest | 0.94 | 1.31 | 0.37 | 1.4 |
A few notes about the table :
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.)
| Test | Java | Python | P-J | P/J |
| ConsoleTest | 143 | 35 | -108 | 0.24 |
| HashTest | 284 | 69 | -215 | 0.24 |
| IOTest | 368 | 76 | -292 | 0.21 |
| ListTest | 413 | 101 | -312 | 0.245 |
| NativeTest a | 261 | 57 | -204 | 0.22 |
| NativeTest b | 172 (563) | 382 | 210 (-181) | 2.22 (0.679) |
| NoTest | 66 | 0 | -66 | 0.0 |
| ObjectTest | 271 | 134 | -137 | 0.494 |
| SpeedTest | 110 | 32 | -78 | 0.29 |
A few notes about this table :
Created and published