Interesting speed benchmark

Mahesh Padmanabhan micronospampad at nospam.yahoo.com
Tue Jun 5 19:49:01 EDT 2001


Hello,

To email me remove "nospam" from the email address.

I came across this web site: 
http://www.twistedmatrix.com/~glyph/rant/python-vs-java.html

in which the author does some (by his own admission) subjective 
benchmarks between java and python. While most of it is usual stuff, the 
one test that stood out was the following:

(I am using a Debian woody system with Python 2.1 and JDK 1.3 from 
blackdown on an Intel system)

Python program:
---------------

class ObjectTest:
         pass

for i in xrange(1000):
     root=ObjectTest()
     for j in xrange(10000):
         root.next=ObjectTest()
         root=root.next

Time:

real    1m23.326s
user    1m23.290s
sys     0m0.060s


Java program:
-------------

public class ObjectTest {
     public ObjectTest next;
     public static void main(String[] args) {
         for (int i = 0; i < 1000; i++) {
             ObjectTest root = new ObjectTest();
             for (int j = 0; j < 10000; j++) {
                 root.next=new ObjectTest();
                 root=root.next;
             }
         }
     }
}

Time:

real    0m2.428s
user    0m2.190s
sys     0m0.220s

There is a huge difference in performance. In fact I tried this under 
Windows NT 4 SP5 with Python 2.1 and jdk1.3 from SUN and got similar 
results.

I am very curious to know why Python takes so much time.

Thanks

Mahesh




More information about the Python-list mailing list