[Tutor] jython slowness

Kent Johnson kent_johnson at skillsoft.com
Mon Oct 25 05:22:06 CEST 2004


That's very strange. I timed the same loop and jython only took about 50% 
longer than python (the timeit module from python 2.3 works fine in jython):
D:\Projects\CB\lib\Lib>jython timeit.py "[i for i in [1,2,3]]"
100000 loops, best of 3: 1.7 usec per loop

D:\Projects>python24 -m timeit "[i for i in [1,2,3]]"
1000000 loops, best of 3: 1.25 usec per loop

The for loop version is considerably slower in jython, a bit slower in python:
D:\Projects\CB\lib\Lib>jython timeit.py -s "l=[]" "for i in [1,2,3]: 
l.append(i)"
100000 loops, best of 3: 4.6 usec per loop

D:\Projects>python24 -m timeit -s "l=[]" "for i in [1,2,3]: l.append(i)"
1000000 loops, best of 3: 1.84 usec per loop

I use Jython 2.1 a lot and I haven't found any serious performance problems.
Kent

At 11:45 PM 10/24/2004 +0100, Alan Gauld wrote:
>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.
>
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list