[Tutor] jython slowness

Alan Gauld alan.gauld at freenet.co.uk
Mon Oct 25 00:45:50 CEST 2004


I occasionally play with jython, especialy when testing java code.

I've been reading the recent New Riders book on Jython and noticed
a couple of the programs could be much shorter using list
comprehensions
so I tried it - wow! Jython is usually between 2-10 times slower than
regular python but comprehensions seem to be at least 50 times slower!

[i for i in [1,2,3]]

took about 5 seconds on my 2Ghz XP box under jython.
Under CPython the same code was nearly instantaneous.

In jython (v2.1) the "equivalent" code:

l=[]
for i in [1,2,3]:
   l.append(i)

is also near instant.

Does anyone on the list know why the comprehension version is soooo
slow?

Alan G.



More information about the Tutor mailing list