On Mar 29, 2010, at 4:15 PM, Soam Vasani wrote:
> Hi all,
> A question about a difference in Jython 2.5 and 2.2 performance.
> I created the following python script:
> import datetime
> total = datetime.timedelta(0)
> def f():
> a = range(1,1000000)
> t1 = datetime.datetime.today()
> t2 = datetime.datetime.today()
> global total
> total = total + (t2-t1)
> print (t2-t1)
> n_iter = 600
> for i in range(1,n_iter):
> print "i = ", i, "average = ", (total/i)
> And I run this script using jython.bat two releases, Jython 2.5.1 and 2.2.1.
> Both are being run on the same JVM, Sun JRE 1.6.0_13.
> On my machine, Jython 2.5.1 averages to about 3.4 sec per call to f.
> Jython 2.2.1 averages to about 0.15 seconds.
> This is probably not the best benchmark, but the difference between Jython 2.2.1 and 2.5.1 is very big, so I'm wondering if I'm missing something.
> 1. Is the speed difference between the two releases of Jython well known and expected, and/or is this benchmark flawed in some way?
> 2. Is there any tuning that can be done with running Jython 2.5.1 to make it faster?
> 3. Is it possible to compile the script to java bytecode under jython 2.5.1? Would that improve the running time?
You should use time.time instead of datetime.today. Generating solid benchmarks on the JVM is challenging, you especially need to take into account warmup of the JIT.
With that being said we may indeed be slower than 2.2 on this bench because our list implementation was rewritten for 2.5 to be based on ArrayList. The reverse method probably hasn't changed much so the culprit is likely sorting
In 2.5 we no longer use a port of CPython's timsort, mostly because it's not easily adapted to the new list implementation. timsort is well known for having incredible performance on pre-sorted lists like in this benchmark.
We now use the JVM's default sort instead. The good news is Java 7 has adopted the better timsort as its own default sort.
We could port the Java 7 timsort implementation for use in earlier JVMs but IIRC we couldn't make it as efficient for in-place sorting as Java 7 does. That's because we can't directly access the underlying array of ArrayLists.