places projects software writing photos

leif > projects >

Python vs. Java Benchmarks

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 !

Runtime performance

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).

TestJavaPythonP-JP/J
ConsoleTest23.3518.01-5.340.7713
HashTest2.083.961.881.90
IOTest5.1323.2618.134.53
ListTest1.485.574.093.76
NativeTest2.433.981.551.64
NoTest1.010.07-0.940.07
ObjectTest2.42110.02107.6045.5
SpeedTest0.941.310.371.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.

Code size

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.)

TestJavaPythonP-JP/J
ConsoleTest14335-1080.24
HashTest28469-2150.24
IOTest36876-2920.21
ListTest413101-3120.245
NativeTest a26157-2040.22
NativeTest b172 (563)382210 (-181)2.22 (0.679)
NoTest660-660.0
ObjectTest271134-1370.494
SpeedTest11032-780.29

A few notes about this table :

More information