[Tutor] jython slowness

Alan Gauld alan.gauld at freenet.co.uk
Tue Oct 26 10:08:40 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

E:\Jython>jython Lib\timeit.py "[i for i in [1,2,3]]"
100000 loops, best of 3: 2.2 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
>

E:\Jython>jython Lib\timeit.py -s "l=[]" "for i in [1,2,3]:
l.append(i)"
100000 loops, best of 3: 6.51 usec per loop

Yes, I now get exactly the same results as you (apart from the fact
my PC is slower! :-) These are the results I'd expect to see since
comprehensions are usually faster than loops.

I don't know what happened yesterday but I tried it two or three times
and the comp took ages, today its just as fast as I'd expect. Wierd.

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

Neither had I in the past, it was measurably slower but not enough
to notice in real usage. I'm starting to use Java beans a lot at work
so  I'm slowly converting from CPython to Jython and the problem
yesterday just confused me completely...

Thanks for the tests.

Alan G.



More information about the Tutor mailing list